Fix diving too deep and rising too slowly at high FPS - #5326
Open
Flashmyname wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
HOOK_CTaskSimpleSwim__ProcessSwimmingResistance(added in #379) scales the whole target velocity bykOriginalTimeStep / 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::CalcBuoyancyForcesubtracts 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:
Checklist