Jump to content

Forwards or Backwards?


Balrog85

Recommended Posts

Hi. I'm completely useless at trigonometry and direction-related code. Could somebody please tell me the easiest way to detect if a vehicle is travelling forwards or backwards (or more towards one of those directions than the other), without the driver necessarily pressing the accelerate or reverse keys. I'm trying to stop my server's drift meter resource from awarding points when the vehicle is travelling backwards, as it's easy to glitch it and get a lot of points by rolling a car backwards, down a hill.

Thanks.

Link to comment

From my old roleplay gamemode back in the days, I hope it can help you. (Its purpose is to check if driver is driving backwards and then do animation out of it.)

function checkBackwardAnimation() 
    if isPedInVehicle(localPlayer) then 
        local veh = getPedOccupiedVehicle(localPlayer) 
        if veh and getVehicleController(veh) == localPlayer then 
            local ax, ay, az = getElementVelocity(veh) 
            local m = getElementMatrix(veh) 
            local rx = ax*m[1][1] + ay*m[1][2] + az*m[1][3] 
            local ry = ax*m[2][1] + ay*m[2][2] + az*m[2][3] 
            local rz = ax*m[3][1] + ay*m[3][2] + az*m[3][3] 
            if ry >= 0 then 
                setElementData(localPlayer, "braking", false) 
            else 
                setElementData(localPlayer, "braking", true) 
            end 
        end 
    end 
end 
addEventHandler("onClientPreRender", root, checkBackwardAnimation) 

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