Skip to content

Fix #2939: Make ped pushing vehicle physics FPS independent - #5199

Open
MohabCodeX wants to merge 6 commits into
multitheftauto:masterfrom
MohabCodeX:fix/ped-push-vehicle-high-fps
Open

Fix #2939: Make ped pushing vehicle physics FPS independent#5199
MohabCodeX wants to merge 6 commits into
multitheftauto:masterfrom
MohabCodeX:fix/ped-push-vehicle-high-fps

Conversation

@MohabCodeX

Copy link
Copy Markdown
Contributor

Fix #2939: Make ped pushing vehicle physics FPS independent

Summary

Fixes an issue where running into vehicles at high FPS causes them to move and slide much faster and easier than at 30 FPS.

Solution

Scaled the vehicle's collision velocity delta by timeStepRatio when pushed by a ped. This keeps the total impulse per second consistent across all framerates and matches the original single-player physics behavior.

Notes & Considerations

Caution

While 100% mathematical parity across all framerates is practically constrained by the underlying GTA physics engine (Euler integration and discrete tire friction steps), this solution represents the closest and most balanced approach without rewriting the physics loop from scratch. Further reviews and community testing are welcome to ensure comprehensive coverage across edge cases.

Testing

Tested by pushing vehicles at 30 FPS vs 100 FPS.

2026-08-17.08-53-28.1.mp4

@FileEX

FileEX commented Aug 17, 2026

Copy link
Copy Markdown
Member

I feel like it's significantly harder to push the vehicle at 100 FPS. Why does it behave like that?

Comment thread Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp
@MohabCodeX

MohabCodeX commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Scaling the impulse by timeStepRatio makes the collision force per second mathematically equal across framerates, but GTA's physics engine still applies tire friction and ground damping on every single frame. At 100 FPS, that friction runs ~3.3x more often than at 30 FPS, which absorbs the smaller per-frame impulses faster before the vehicle can build up momentum (and the per-frame penetration depth that shifts the car is also naturally smaller).

We could tweak it with something like std::sqrt(timeStepRatio) in HOOK_CPhysical__ApplyCollision to compensate for the extra friction steps and make pushing feel noticeably lighter at high FPS. I attached a video demonstrating this approach in action for comparison. You might want to test it yourself too.. personally, I wasn't entirely convinced by it compared to the clean linear ratio since it introduces an arbitrary curve into the physics, but it does make pushing easier while still preventing the launch bug. Another route could also be looking into a dedicated custom ped-push velocity system when colliding with vehicles.

2026-08-17.08-42-20.1.mp4

@FileEX

FileEX commented Aug 19, 2026

Copy link
Copy Markdown
Member

It looks much better now

@FileEX

FileEX commented Aug 21, 2026

Copy link
Copy Markdown
Member

Tested and it generally works, but it introduces a noticeable side effect, even at normal FPS.

With your PR, the vehicle behaves strangely - it seems to bounce and lock its wheels, making it harder to move.

74 FPS without your PR (smooth)
https://files.catbox.moe/8m1zau.mp4

74 FPS with your PR (rough, vehicle bounces)
https://files.catbox.moe/qa060h.mp4

@FileEX FileEX added the bugfix Solution to a bug of any kind label Aug 21, 2026
@Haxardous Haxardous moved this to In progress in Framerate Fixes Aug 23, 2026
@FileEX FileEX added the feedback Further information is requested label Aug 30, 2026
Copilot AI lite review requested due to automatic review settings September 7, 2026 01:41

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings September 7, 2026 01:42
@MohabCodeX

MohabCodeX commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Quick update: After further investigation into the vehicle physics, I found that the previous implementation simply scaled raw collision impulses after impact, which didn't account for directional force distribution or tire physics. The new approach isolates horizontal rolling velocity from the vertical and tilt axes, governs forward acceleration and top speed using momentum conservation, and dynamically scales the vehicle sleep threshold with delta time so suspension settling stays consistent across framerates. I'll attach a video later

Vehicle push behavior is now standardized to the 30 FPS baseline across all framerates. GTA:SA physics were tuned for 30 FPS,.. this prevents high-FPS collision impulses from breaking tire friction and causing vehicles to glide.

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings September 7, 2026 01:47

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings September 7, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment thread Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp
Comment thread Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp
Copilot AI review requested due to automatic review settings September 9, 2026 12:56
@MohabCodeX
MohabCodeX force-pushed the fix/ped-push-vehicle-high-fps branch from 84cf074 to bb4481e Compare September 9, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

constexpr float kOriginalTimeStep = 50.0f / 30.0f;

// Fixes player movement issue while aiming and walking on high FPS.
// Only rescales the compare threshold; m_MoveCmd's reset is NOPed separately in InitHooks_FrameRateFixes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Comment on lines -912 to -914
// Fixes camera jitter while aiming and walking at high FPS.
// CTaskSimpleUseGun::SetMoveAnim
MemSet((void*)0x61E5E4, 0x90, 0x6);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental deletion during rebase .. restored now

Copilot AI review requested due to automatic review settings September 9, 2026 14:16
@MohabCodeX
MohabCodeX force-pushed the fix/ped-push-vehicle-high-fps branch from bb4481e to b150d7b Compare September 9, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

… at high FPS

Spawned unoccupied vehicles at high framerates (e.g. 240 FPS) were going
to sleep with their suspension fully extended/stretched, only settling to
normal ride height when bumped by a player.

This was caused by two issues in GTA:SA vehicle control:
1. The isVehicleIdle flag (0x6B1AF5 in CAutomobile, 0x6B9850 in CBike)
   forced instant sleep on frame 1 before gravity could settle the chassis.
2. Stationary parking damping in CAutomobile (0x6B361C) and CBike (0x6BC18F)
   wiped moveSpeed.z to 0 whenever speed was below 0.0045f. At 240 FPS, one
   frame of gravity is only 0.00166f (< 0.0045f), so vertical speed was
   erased on every single frame, preventing the springs from ever compressing.

Changes:
- NOP'd the isVehicleIdle instant-sleep flag in CAutomobile and CBike.
- NOP'd moveSpeed.z zeroing in stationary damping so parking brakes only
  affect horizontal movement and yaw.
- Scaled the 0.0045f stillness threshold by (timeStep / kOriginalTimeStep)
  across all comparison sites to maintain consistent sensitivity.
- Scaled the sleep frame threshold by (kOriginalTimeStep / timeStep) to
  keep an invariant ~333 ms stillness window.

Tested at 240 FPS with newly spawned vehicles; suspension now compresses
and settles to normal ride height immediately on spawn without player touch.
Copilot AI review requested due to automatic review settings September 10, 2026 16:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 10, 2026 16:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@FileEX

FileEX commented Sep 10, 2026

Copy link
Copy Markdown
Member

Please resolve conflicts

…cle-high-fps

# Conflicts:
#	Client/multiplayer_sa/CMultiplayerSA_FrameRateFixes.cpp
Copilot AI review requested due to automatic review settings September 10, 2026 23:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@MohabCodeX

Copy link
Copy Markdown
Contributor Author

While testing across framerates, noticed vehicles spawned at high FPS (100–240) were freezing with stretched suspension because the game was putting them to sleep on frame 1 before gravity could settle the chassis onto the springs.

Disabled the instant-sleep bypass and stopped stationary damping from wiping small vertical gravity steps. Cars and bikes now settle naturally to their proper resting ride height across all framerates before going to sleep.

Full Testing : https://streamable.com/3puhud

Copilot AI review requested due to automatic review settings September 11, 2026 14:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings September 12, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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 feedback Further information is requested

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

At high FPS it's easier to move cars around by running into them

4 participants