Fix isPedOnGround#4317
Conversation
|
I have tested this PR and confirms it fixes isPedOnGround being unreliable, when you were moving on a slope isPedOnGround would flicker between true/false now it stays on true. This might not seem like an important fix, but it might be the reason why there is significant player movement desync where players can be seen moving forwards and then snapping back when the next puresync packet arrives because IsOnGround is used in puresync so if 1 puresync update sends you as not on ground it can cause this: "they’re flagged as airborne. While flagged airborne, puresync enables velocity-based prediction with little or no friction, so the remote player keeps sliding forward even after their real movement stops" This desync is brought up a lot by players, so if this does fix it, they'd be very happy. And at the very least it'd fix this function which is also itself quite a useful fix. |
|
Nice, this will likely be backported to the next 1.6.0 build that'll also be circulated, so it can be of use before the release of 1.7 |
#### Summary This PR fixes the isVehicleOnGround function similarly to how #4317 fixed IsPedOnGround. The current logic is very primitive. It simply checks the distance from the bottom of the bounding box to the ground. That’s why if a vehicle is, for example, lying on its roof, it returns false. It can also return false on slopes, and for a Monster Truck it always returns false, because its wheels aren’t included in the bounding box, which ends at the model’s edge. <img width="936" height="554" alt="image" src="https://github.com/user-attachments/assets/e8d5fd41-1afa-42f1-b72e-fd2c715fba46" /> The fixed isVehicleOnGround function now first does a simple check to see if any wheel is touching the ground. If so, the vehicle is considered on the ground. If not, it performs a basic OOB check and measures the distance to the ground. During testing, I never received a false negative. #### Motivation Fixed #471 and #2093 #### Test plan Tested. ``` Spawn Monster Truck crun isVehicleOnGround(me.vehicle) -- always false ``` ``` Spawn Beagle crun setVehicleDamageProof(me.vehicle, true) crun me.vehicle.rotation = Vector3(0, 180, 0) crun isVehicleOnGround(me.vehicle) -- false ``` ``` Spawn some car crun setVehicleHandling(me.vehicle, 'suspensionLowerLimit', -1) crun isVehicleOnGround(me.vehicle) -- false ``` #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
Fixed #534
Original author: #1603
In addition to fixing the precision of
IsOnGround, this PR adds acheckVehiclesargument that allows specifying whether the function should return true if the ped is standing on a vehicle (by default it returns false, as before).