Repository navigation
Conversation
…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.
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.
|
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. 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. |
Summary
Fixes bikes (BMX, bicycles, motorbikes) swinging left and right while standing still on high FPS.
CBike::ProcessControlleans the bike and rider by their sideways acceleration: the sideways speed change within the frame divided byGRAVITY * 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 = 0and server FPS limit 0, logging the lean every frame: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