Jump to content

Vehicle rotations (rotX,rotY,rotZ)


XFawkes

Recommended Posts

Everyone knows that we can rotate cars in air using arrows:

up/down - 33465015.jpg (backflip/noseflip)

left/right - imageskopia.jpg (barrel)

SPACEBAR+left/right - imageskopia2.jpg

I've already checked Rotations when car is doing flips.

When we are doing backflip/noseflip only rotX value is changing. (That's correct)

When we are turning left/right (+spacebar) only rotZ value is changing. (That's correct)

but When we are doing barrel left/right imageskopia.jpg then when we are on roof (wheels are on top) rotX = 180, rotY = 0, rotZ = 180 (It is the same as: rotX=0, rotY=180, rotZ=0). How can i calculate it to:

rotX=0, rotY=180, rotZ=0 , because I want to make stunt script.

I hope you can understand me :)

Link to comment

This is the base code to get element rotation instead of what you may be using now (getElement/Vehicle/Rotation() ? )

The code gives correct pitch/roll/yaw values even while upsidedown.

local m = getElementMatrix( theVehicle ) 
local pitch = math.deg( math.asin( m[2][3] ) ) -- (-90,90) 
local roll = math.deg( math.atan2( m[1][3], m[3][3] ) ) --(-180,180) 
local yaw = math.deg( math.atan2( m[2][1], m[2][2] ) ) --(-180,180) 

You can get rid of negative values if you need to, should be easy done.

Link to comment

Nah, when I am doing pitch then pitch value goes to 0 and roll and yaw goes to 180...

I need this:

When i am doing Pitch (or changing X rotation) then Pitch value is 180 and others 0,0

When i am doing Roll (or changing Y rotation) then Roll value is 180 and others 0,0

(etc.)

I don't want this:

0,0,180 = 180,180,0

0,180,0 = 180,0,180

180,0,0 = 0,180,180

Link to comment

How are you going to determine whether it was pitch or roll made the vehicle upside-down?

If you pitch the vehicle and it goes through this point, you want rotX to be 180, but while you roll the vehicle it still goes through the same position. Also if the vehicle make the full loop, the rotation drops back to 0.

So please tell us how do you calculate stunt bonus.

Link to comment

You have 2 typical states for the vehicle "normal" and "upside-down". So since roll and yaw changes +/-180 when the vehicle goes from one state to another, you need to check if the new vehicle state is the same as it used to be on last frame. If not - do not add the rotation and resume calculations when the condition is met.

Link to comment

Can you explain it to me better, because I don't get it.

I was trying with: when x,z = 0 and in 3-4 frames it goes to 180 then outputtext("going upsede-down") but it is not a good idea, sometimes it shows me that even if I am in a "normal" state ..

Link to comment

Basically I was trying to say you need to detect going upside-down and back somehow and either skip the stunt calculations for the moment or calculate in another way, fixing pitch/roll/yaw values or whatever. That's it. Sorry, I can't get you any details now, I haven't been thinking deep into this issue =/

P.S. Can't getVehicleTurnVelocity() be used alternatively?

Link to comment

When car is rolling right then Rotation Y goes like:

0,45,90,45,0,315,270,315,0

I've already created script which checks when car is in normal position and when it is upside-down. And I've already used getVehicleTurnVelocity to check if it was pitch or roll [to do upside-down] state.

x,y,z = vehiclerotations

onClientRender:

function createText ( ) 
 if x > 90 and x < 270 then 
        if State ~= 1 then 
            State = 1 
            Check(State,x,y,z) 
        end 
        dxDrawText( "UPSIDE-DOWN", 0, 100, screenWidth, screenHeight/6, tocolor ( 255, 255, 255, 255 ), 3, "pricedown" ,"center","center") -- my debug 
    else 
        if State ~= 0 then 
            State = 0 
            Check(State,x,y,z) 
        end 
        dxDrawText( "NORMAL", 0, 100, screenWidth, screenHeight/6, tocolor ( 255, 255, 255, 255 ), 3, "pricedown" ,"center","center") -- my debug 
    end 
    ox,oy,oz = x,y,z 
end 
  
function Check(Stan,x,y,z) 
    if Stan == 0 then -- change to normal 
     
    elseif Stan == 1 then -- change to upside-down 
        local vx,vy,vz = getVehicleTurnVelocity ( gMeV ) 
        if vy > vx then 
            outputChatBox("Roll") 
        else 
            outputChatBox("Pitch") 
        end 
    end 
end 

Now i am thinking how to calculate that:

0+45+90+45+0+315+270+315+0 = 360 :)

EDIT:

OMG: x-TurnVelocity has the same problem, when i am doing Roll then it goes to high values... I think turnvelocity just checks rotation changes.... So it won't help me..

:evil:

I don't know how to do it...

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