Skip to content

Fix bikes swinging left and right while idle on high FPS - #5511

Open
OsamaDevL wants to merge 4 commits into
multitheftauto:masterfrom
OsamaDevL:fix/bike-swing-high-fps
Open

OsamaDevL wants to merge 4 commits into
multitheftauto:masterfrom
OsamaDevL:fix/bike-swing-high-fps

Conversation

@OsamaDevL

Copy link
Copy Markdown

Summary

Fixes bikes (BMX, bicycles, motorbikes) swinging left and right while standing still on high FPS.

CBike::ProcessControl leans the bike and rider by their sideways acceleration: the sideways speed change within the frame divided by GRAVITY * time step (0x6BBAD6..0x6BBB13). An idle bike rocks very slightly (~0.26°), and the tyres holding the wheels in place give it a sideways push that depends on the roll speed, not on the time step. At high FPS that push is divided by a much smaller time step, so the invisible rocking becomes a visible side to side lean.

Above 30 FPS the acceleration is now measured from the bike's start-of-frame speed across one 30 FPS frame (bWouldBeNewFrame). At 30 FPS and below the original formula is kept, and between 30 and 60 FPS the two are blended by frame time so the lean doesn't jump between them. Bikes in the air or attached to something keep the original code.

Motivation

Fixes #4658

Test plan

Local server, BMX, fps_limit = 0 and server FPS limit 0, logging the lean every frame:

  • Idle lean noise (sd): 30 FPS 0.0033, 60 FPS 0.0036 (was 0.011), unlimited ~240 FPS 0.0059 (was 0.080). No visible swing any more.
  • Turning: the fixed lean follows the original formula (corr 0.96, same direction in 97% of frames), so riding is unchanged.
  • At 30 FPS and below the result is identical to the original.

To check: unlock the FPS, sit on a BMX on flat ground without touching any keys and watch the rider; before this change they sway left and right, after it they stay still.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

…uto#4658)

CBike::ProcessControl leans the bike and rider by their sideways
acceleration: the sideways speed change within the frame divided by
(GRAVITY * time step). An idle bike rocks very slightly (~0.26 deg), and
the tyres holding the wheels in place give it a sideways push that
depends on the roll speed, not the time step. At high FPS that push is
divided by a much smaller time step, so the invisible rocking becomes a
visible side to side lean of the bike and rider.

Above 30 FPS, measure the acceleration from the bike's start-of-frame
speed across one 30 FPS frame instead. At 30 FPS and below the original
formula is kept, and between 30 and 60 FPS the two are blended by frame
time so the lean doesn't jump between them.

Tested on a local server with a BMX, logging the lean every frame:
- Idle lean noise (sd): 30 FPS 0.0033, 60 FPS 0.0036 (was 0.011),
  unlimited ~240 FPS 0.0059 (was 0.080). No visible swing any more.
- Turning: the fixed lean follows the original (corr 0.96, same
  direction 97% of frames), so riding is unchanged.
@FileEX FileEX added the bugfix Solution to a bug of any kind label Oct 29, 2026
@FileEX FileEX moved this to In progress in Framerate Fixes Nov 9, 2026
Addresses FileEX's review on multitheftauto#5511: GetBikeLeanAcceleration read the bike
through raw offsets on a void pointer. It now takes a CBikeSAInterface* and
reads named fields (m_pAttachedEntity, m_cNumContactWheels, bDisableFriction,
m_vecGroundRight).

The ground right vector at 0x624 sat inside CBikeSAInterface::pad1, so pad1
is split into pad1[15] + m_vecGroundRight. The layout is unchanged; static
asserts check the offsets of m_vecGroundRight (0x624) and m_cNumContactWheels
(0x804) next to the existing size check.

The asm hook keeps its two byte offsets, since the codebase does not use the
inline asm struct member syntax; their comments now name the fields.

Tested: Game SA and Multiplayer SA build in Release. In game at 30, 60, 240
and ~480 FPS the lean value stays at 0 on an idle BMX, the same as before
this change.
@OsamaDevL

OsamaDevL commented Nov 10, 2026 •

Copy link
Copy Markdown
Author

Retested this. My first retest accidentally used a build that still had my local Vulkan work files in it, so the FPS went above 400 and the swing showed up again. I logged the bike at 30, 60, 240 and ~480 FPS to see what’s going on

The lean part is fixed at every FPS. On an idle BMX at ~480 FPS, the original lean formula swings between its ±1.62 limits, and the fixed value stays at 0. The rider’s lean animation doesn’t move either.
Above ~250 FPS there’s a second, separate problem. Once the bike has moved, the bike itself starts physically rocking side to side, and the rocking never dies out (it does at 30 and 78 FPS). It isn’t caused by MTA’s bike patches it still happens with the rapid stop fix and the bike stillness patches turned off. It looks like GTA’s own bike balancing code applies a force every frame without scaling it by the time step.

Fixing that second part for any FPS would mean hooking GTA’s bike balancing code and scaling that force by the time step. I’m not sure that’s doable without digging into GTA’s code, so I’d keep it out of this PR.

Since there’s no Vulkan support for now, this PR is fine to merge as it is it fixes the leaning issue.

@OsamaDevL
OsamaDevL requested a review from FileEX November 10, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Solution to a bug of any kind

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

High FPS causes bikes to swing

2 participants