Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getVehicleCurrentGear() returns gear 1 while driving very slow backwards #503

Open
Einheit-101 opened this issue Sep 18, 2018 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@Einheit-101
Copy link

Einheit-101 commented Sep 18, 2018

Describe the bug

As the summary says, i can drive very slow backwards but getVehicleCurrentGear does return gear 1 instead of 0.

To Reproduce

  1. Take a slow car, and drive one meter forward (gear = 1)
  2. Stop and use the handbrake (so you dont get too fast) and drive some millimeters backwars.
  3. Now open console and use runcode: crun getVehicleCurrentGear(getPedOccupiedVehicle(localPlayer))
  4. 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.

From https://bugs.mtasa.com/view.php?id=8562

@ArranTuna ArranTuna added the bug Something isn't working label Sep 19, 2018
@botder botder added this to the Backlog milestone Mar 3, 2019
@Pirulax
Copy link
Contributor

Pirulax commented Nov 13, 2020

Probably related to some floating point accuracy rounding in GTA.
@TheNormalnij maybe has more idea about this tho.

@TheNormalnij
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants