Open Einheit-101 opened 6 years ago
Probably related to some floating point accuracy rounding in GTA. @TheNormalnij maybe has more idea about this tho.
cTransmission::InitGearRatios at 0x6D0460
v1->m_aGears[offsetof(cTransmission, m_aGears)].m_fChangeUpVelocity = -0.0099999998;
v1->m_aGears[offsetof(cTransmission, m_aGears)].m_fChangeDownVelocity = v8;
v1->m_aGears[1].m_fChangeDownVelocity = -0.0099999998;
constant -0.0099999998
can be changed
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