Skip to content

Fix diving too deep and rising too slowly at high FPS - #5326

Open
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/3344-dive-depth-fps
Open

Fix diving too deep and rising too slowly at high FPS#5326
Flashmyname wants to merge 1 commit into
multitheftauto:masterfrom
Flashmyname:fix/3344-dive-depth-fps

Conversation

@Flashmyname

@Flashmyname Flashmyname commented Sep 5, 2026

Copy link
Copy Markdown

Summary

HOOK_CTaskSimpleSwim__ProcessSwimmingResistance (added in #379) scales the whole target velocity by kOriginalTimeStep / timestep. That is correct for x and y, which come from the per-frame animation shift, but the dive velocity in z and the buoyancy of the underwater swim state are absolute speeds, so both ended up scaled by fps / 30 as well. This PR scales those two constants back at the instruction that loads them.

The depth is only half of it. cBuoyancy::CalcBuoyancyForce subtracts the entity's vertical momentum from the buoyancy impulse, but the impulse is scaled by the timestep and the momentum is not, so at high frame rates the damping starts well below the 30 FPS rise speed and a surfacing ped is held under. The momentum is now scaled the same way, for peds only, so vehicles and objects are untouched.

Motivation

Fixes #3344. With an uncapped frame rate a dive goes far deeper than the game allows: twice as deep at 60 FPS as at 30, roughly eight times as deep at 240. Once the depth is corrected the ascent turns out to be wrong in the other direction.

Test plan

Tested in game on open water, with the client frame limit and vsync off:

  1. Press the dive control once from the surface and note the lowest z reached, and how long it takes to get back to the surface.
  2. Repeat at 30, 60, 120, 240 and uncapped.
  3. The depth is now the same at every frame rate, and the time back to the surface matches the 30 FPS run.

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.

Scale the dive speed, the underwater buoyancy and the vertical momentum of the
buoyancy damping against the timestep, so swimming matches the 30 FPS game at
any frame rate.

Fixes multitheftauto#3344.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diving at high fps makes your character dive too depth

1 participant