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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

Client-side indeed.

Yes, this is what I need. I think I can achieve this with getVehicleRotation, as said - for X and Z - it's fine.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

I'll give it a try, thanks.

That math makes me scary o_O

And if it returns in -180, 180 i can easly add 180 to get 0-360 :P

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

okay, but i dont want to flip the car to the roof, i want some values between.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

so?

i don't get you..

do you see a way to flip car into two wheels with only rotating on Z, X, and leaving Y in 0-90 and 270-360?

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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