Skip to content

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

Merged
FileEX merged 8 commits into
multitheftauto:masterfrom
MohabCodeX:fix/ped-push-vehicle-high-fps
Sep 19, 2026
Merged

FileEX merged 8 commits into
multitheftauto:masterfrom
MohabCodeX:fix/ped-push-vehicle-high-fps

Conversation

@MohabCodeX

@MohabCodeX MohabCodeX commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Closes #2939

Summary of Changes

Running into unoccupied vehicles at high framerates causes them to accelerate and slide unnaturally fast due to frequent collision impulses overpowering tire friction.

This PR governs pedestrian push impulses by:

  • Capping push velocity using momentum conservation based on ped and vehicle mass.
  • Scaling collision impulses by framerate timestep to maintain consistent vehicle weight across all FPS levels.
  • Preserving vertical and roll/pitch stability to prevent vehicles from tilting or flipping during contact.

Testing

https://streamable.com/3puhud

@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.

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 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
@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.

Comment thread Client/mods/deathmatch/logic/CClientGame.cpp Outdated
Comment thread Client/multiplayer_sa/CMultiplayerSA.cpp Outdated
Comment thread Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp Outdated
Comment thread Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp Outdated
Comment thread Client/multiplayer_sa/CMultiplayerSA_CrashFixHacks.cpp Outdated
@FileEX

FileEX commented Sep 16, 2026

Copy link
Copy Markdown
Member

Something is still wrong. At 74 FPS, the vehicle now feels significantly heavier than it normally does.

74 FPS without your PR
https://files.catbox.moe/8ga788.mp4

74 FPS with your PR
https://files.catbox.moe/i0tc9r.mp4

@MohabCodeX

MohabCodeX commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Yes, as I mentioned, I adjusted the car’s movement to match the original 30 FPS behavior. So players at 74 FPS may feel like it’s slower, but it’s actually just behaving the same as it does at 30 FPS, keeping things consistent across all frame rates.

https://streamable.com/3puhud

@MohabCodeX

Copy link
Copy Markdown
Contributor Author

@FileEX The unrelated changes you mentioned are fixes for crashes that actually occurred because of the changes in this PR while testing, mainly vehicles crashing when repeatedly spawned or deleted during tests, and a crash if a vehicle gets destroyed during the collision event. That's why I bundled them together here, but if you still prefer to keep this PR focused on the ped push physics and move those into a separate PR, I have no problem doing that at all

@FileEX

FileEX commented Sep 18, 2026

Copy link
Copy Markdown
Member

@FileEX The unrelated changes you mentioned are fixes for crashes that actually occurred because of the changes in this PR while testing, mainly vehicles crashing when repeatedly spawned or deleted during tests, and a crash if a vehicle gets destroyed during the collision event. That's why I bundled them together here, but if you still prefer to keep this PR focused on the ped push physics and move those into a separate PR, I have no problem doing that at all

I admit that I don't quite understand how you're running into these issues/crashes, since your PR doesn't use any of these functions, such as AllocateMatrix, UpdateRwMatrix, or Set/GetClumpAlpha. So maybe your code is breaking something?

If this were an issue with Set/GetClumpAlpha or the matrix functions, these crashes would have been happening years ago and would be much more common among players.

@MohabCodeX

Copy link
Copy Markdown
Contributor Author

Yeah, it seems I didn't explain the crash fixes clearly enough. Basically, while testing the physics at high FPS, I also fixed an issue where spawned vehicles were going to sleep instantly on frame 1 with their suspension stretched up, so I prevented that premature sleep so they could settle naturally. But keeping them awake during those first spawn frames caused GTA to run things like UpdateClumpAlpha and matrix updates before the clump was even initialized, which immediately crashed the game at 0x732B2A and 0x59AD76. So I just added those hooks as shields to prevent those crashes from happening. But if you prefer to keep this PR strictly about the ped push physics and move the spawn-sleep fix and its crash hooks to a separate PR, I can easily split them.

…nsion fixes

Isolate ped push vehicle physics (multitheftauto#2939) into this PR. Remove vehicle suspension premature sleep fixes and crash defense hooks to be submitted in a separate dedicated pull request.
Copilot AI review requested due to automatic review settings September 18, 2026 21:23

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 18, 2026 21:35

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

Here it's : #5429

@FileEX

FileEX commented Sep 19, 2026

Copy link
Copy Markdown
Member

Well, I'm not sure whether changing the behavior of vehicles even at 60 FPS, which everyone has been used to for years, is a good idea, but okay. Worst case, if people complain about it, we can revert it or find another solution.

@FileEX FileEX added this to the 1.7 (Current) milestone Sep 19, 2026
@FileEX
FileEX merged commit ea21e81 into multitheftauto:master Sep 19, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Framerate Fixes Sep 19, 2026
@FileEX FileEX removed the feedback Further information is requested label Sep 19, 2026
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: Done

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