You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the summary says, i can drive very slow backwards but getVehicleCurrentGear does return gear 1 instead of 0.
To Reproduce
Take a slow car, and drive one meter forward (gear = 1)
Stop and use the handbrake (so you dont get too fast) and drive some millimeters backwars.
Now open console and use runcode: crun getVehicleCurrentGear(getPedOccupiedVehicle(localPlayer))
It may output "1" as current gear. If you were too fast, it does output 0.
Expected behavior
This function should always return 0 when driving backwards.
Multi Theft Auto v1.5.6-release-14394
Additional context
Workaround:
local matrix = getElementMatrix(veh)
local vx, vy, vz = getElementVelocity(veh)
local velocityDir = Vector3(vx, vy, vz)
velocityDir:normalize()
local forwardDir = Vector3(matrix[2][1], matrix[2][2], matrix[2][3])
local dotproduct = velocityDir:dot(forwardDir)
if dotproduct > 1 then dotproduct = 1 end
-- dot sometimes returns values slightly higher/lower than 1/ -1
--this seems to be a bug, so we clamp the values to avoid errors
if dotproduct < -1 then dotproduct = -1 end
local drivingForwards = math.acos(dotproduct) < math.pi / 2
instead of
if getVehicleCurrentGear(veh) == 0 then
you can now use
if not drivingForwards then
and there will be no bug.
Describe the bug
As the summary says, i can drive very slow backwards but getVehicleCurrentGear does return gear 1 instead of 0.
To Reproduce
Expected behavior
This function should always return 0 when driving backwards.
Multi Theft Auto v1.5.6-release-14394
Additional context
Workaround:
local matrix = getElementMatrix(veh)
local vx, vy, vz = getElementVelocity(veh)
local velocityDir = Vector3(vx, vy, vz)
velocityDir:normalize()
local forwardDir = Vector3(matrix[2][1], matrix[2][2], matrix[2][3])
local dotproduct = velocityDir:dot(forwardDir)
if dotproduct > 1 then dotproduct = 1 end
-- dot sometimes returns values slightly higher/lower than 1/ -1
--this seems to be a bug, so we clamp the values to avoid errors
if dotproduct < -1 then dotproduct = -1 end
local drivingForwards = math.acos(dotproduct) < math.pi / 2
instead of
if getVehicleCurrentGear(veh) == 0 then
you can now use
if not drivingForwards then
and there will be no bug.
From https://bugs.mtasa.com/view.php?id=8562
The text was updated successfully, but these errors were encountered: