Jump to content

Vehicle rotation Y problem, strange thing


dzek (varez)

Recommended Posts

Posted

Uhm,

I thought the times I was noob in scripting are gone o.O

I'm having a vehicle.

I'm setting its rotation with setVehicleRotation

and I'm getting strange results with getVehicleRotation.

On X and Z axis it's ok, strange thing happens only with Y axis.

Testing function:

  
function vehTest(veh) 
  ry = 0 
  xx,yy,zz = getElementPosition(veh) 
  setVehicleFrozen(veh, true) 
  setElementPosition(veh, xx,yy,zz+10) 
  try = 0 
  setTimer(function() 
    try = try + 1 
    setVehicleRotation(veh, 0, ry, 0) 
    local rotX, rotY, rotZ = getVehicleRotation(veh) 
    outputConsole(rotY.." -- "..ry) 
    ry = ry + 10 
    if (try==37) then setVehicleFrozen(veh, false) end 
  end, 100, 37, veh, ry) 
end 
  

Results:

  
0 -- 0 
10 -- 10 
20 -- 20 
30 -- 30 
40 -- 40 
50 -- 50 
60 -- 60 
70 -- 70 
80 -- 80 
90 -- 90 
80 -- 100 
70 -- 110 
60 -- 120 
50 -- 130 
40 -- 140 
30 -- 150 
20 -- 160 
10 -- 170 
0 -- 180 
350 -- 190 
340 -- 200 
330 -- 210 
320 -- 220 
310 -- 230 
300 -- 240 
290 -- 250 
280 -- 260 
270 -- 270 
280 -- 280 
290 -- 290 
300 -- 300 
310 -- 310 
320 -- 320 
330 -- 330 
340 -- 340 
350 -- 350 
0 -- 360 
  

I see no way to determine if car is rotated Y by 110 or 70 deg. with this :|

Posted

That's because rotating vehicle 180 degrees on Y axes is the same as rotating it on X and Z axes, both 180 degrees. So you could use X rotation to check if the vehicle is upside down, and if it is, then ry value must be set to 180-ry.

Posted

lol, you are wrong.

you can rotate it by Z - like turning left or right

rotate by Y - like make it drive on two wheels

and rotate by X - to make it "stand" on it's hood.

How you want to achieve to flip car to two wheels with only Z and X?

give me values, and i will agree with you :P

Posted (edited)

I've figured out this works fine:

m = getElementMatrix( vehicle ) 
pitch = math.deg( math.asin( m[2][3] ) ) 
roll = math.deg( -math.atan2( m[1][3], m[3][3] ) ) --I need the minus, you may not 
yaw = math.deg( math.atan2( m[2][1], m[2][2] ) ) 
if yaw < 0 then 
    yaw = yaw + 360 
end 

The roll goes [-180, 180]

Edited by Guest
Posted
lol, you are wrong.

you can rotate it by Z - like turning left or right

rotate by Y - like make it drive on two wheels

and rotate by X - to make it "stand" on it's hood.

rotate 180 degrees by Z - reverse its direction

rotate 180 degrees by Y - make it stand on its roof

rotate 180 degrees by X - make it stand on its roof, but the direction will be the opposite than rotating by Y

So if you flip car by X and Z, it will be the same as flipping it by Y.

And the way of getting Y rotation Antibird wrote here is a bit similar to the one I suggested.

Posted

You say you don't want to flip it to the roof, but you see it as a problem when it's flipped and Y rotation is still shown to be below 90 degrees :)

Posted

Do you see a way to flip car onto two wheels with matrices? There's no such function like setElementMatrix. But the code Antibird posted was for getting the rotation, not setting it, and I'm talking about another, similar way to do that.

Posted

okaaay, well, i dont need to set such rotation, but to get it, so well, I'm fine now

thanks to you both, even i have no idea how can i GET "correct" rotation with only X,Z and math :P

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...