How to gracefully reset a vehicle after unpossess? Multiplayer.

NODARYN
Sat, 07 Dec 2024 00:29:03 +0000
Programming & Scripting

I’m developing an online game where the character can drive vehicles.
If a player exits the vehicle while holding the “accelerate” button (e.g., moving forward), the vehicle continues to move even after the player leaves the driver’s seat.

I’m not talking about inertia—this is specifically about the engine continuing to apply force.
It looks like the player left a brick on the gas pedal before exiting the vehicle.

I need to clarify that I’m using physics prediction, which operates under entirely different mechanisms.
I’ve tried using the built-in functions of ChaosVehicleMovement, but they don’t provide anything useful for this scenario.
I don’t need the vehicle to stop instantly, like ResetVehicle() or StopMovementImmediately() do (which, by the way, don’t work with physics prediction).
Additionally, clearing all inputs before exiting the vehicle has no effect.

After investigating how input data is sent internally, I realized the client buffers inputs and sends them to the server via RPC at a defined interval.
This means that if the player exits the vehicle, they may not have time to send the updated (cleared) inputs to the server.
As a result, the server continues controlling the vehicle based on the last received (cached) inputs.
This is the core of the problem.

I have one working method that I will use until I find a full-fledged solution: I reset the inputs, wait about 0.3 seconds and send a request to the server to leave the transport. This works, but adds a visible delay to the client. In addition, I have not tested this method on the build, and there is also a possibility of packet loss, since sending Inputs is unreliable.

I could try overriding the UNetworkPhysicsComponent class to modify some of its logic, but I’m looking for a way to solve this without overriding engine classes or patching the engine.
Has anyone encountered this situation before?

P.S. If you’re working on a single-player game and everything works fine for you, your suggestions won’t help here. Everything also works perfectly for me in standalone mode.
The issue only occurs when playing as a client because the client doesn’t send updated data to the server in time before exiting the vehicle.

3 posts - 2 participants