Server authoritative vehicle movement in a netcode for gameobjects multiplayer game

Hi,

I am making a racing like game where bot-vehicles use predefined waypoint circuit to move around the map. My vehicle controlling script uses wheelcoliders and rigidbody to control the motion of the object.

Currently to synchronize vehicle position/rotation I simply use network transform/network rigidbody on the prefab but this causes visuals like wheel spinning, exhaust and brake lights to not work at all, they are just static since their functionality is dependent on the inputs to the rigidbody (velocity and wheelcolider motorTorque for example)

I tried to change the approach and have a server authoritative waypoint path tracker that guides the vehicle to the position they should move next, and doing so the physics is be calculated locally per connected client, but the issue with this method is that the actual position of the vehicle on client side will not match the position of the same vehicle on the server.

I have read about client prediction and reconciliation but I am not sure if this applies to my particular issue since the client does not control the actual vehicle, its just a automated bot that should follow the waypoint.

So I feel a bit lost here, I would appreciate some guidance on how cases like this are handled in a multiplayer games

Then you need to decouple that and/or synchronize it separately.

One cheap way to do this without synchronization is to keep the vehicle’s previous position and velocity on the client side. Then you can calculate on the client side what its velocity is var velocity = (position - prevPosition).magnitude. You have to do it manually because the client-side rigidbody is kinematic but do check if NetworkRigidbody actually syncs the velocity property. If so you can just use that and only need to remember the past velocity.

Then compare it with the previous velocity and if the difference between the two is greater than a certain threshold, and also lower than the previous, you light up the brake lights. For the wheel spin you can just rotate the wheels by an amount based on velocity.

Generally it’s best practice to decouple input from any actions that follow but it’s even more important for networking.