Advertisement
StrixG

getVehicleDriftAngle

Nov 4th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.58 KB | None | 0 0
  1. function getVehicleDriftAngle(theVehicle)
  2.     if getElementType(theVehicle) ~= "vehicle" then
  3.         return false
  4.     end
  5.  
  6.     local vX, vY = getElementVelocity(theVehicle)
  7.     if (vX == 0.0 and vY == 0.0) then
  8.         return 0.0
  9.     end
  10.  
  11.     local rotX, rotY, rotZ = getElementRotation(theVehicle)
  12.    
  13.     local moveDirection = math.deg(-math.atan2(vX, vY))
  14.  
  15.     if rotZ > 180 then
  16.         rotZ = rotZ - 360
  17.     end
  18.    
  19.     local driftAngle = moveDirection - rotZ;
  20.  
  21.     if driftAngle < -180.0 then
  22.         driftAngle = driftAngle + 360.0
  23.     elseif driftAngle > 180.0 then
  24.         driftAngle = driftAngle - 360.0
  25.     end
  26.     return driftAngle
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement