Jump to content

Vehicle rotation Y problem, strange thing


dzek (varez)

Recommended Posts

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 :|

Link to comment

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
Link to comment
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.

Link to comment

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...