I don't fully understand how client side prediction works with authoritative movement.
Let's say we have:
- client at position(0,0)
- server at position(0,0)
Now the client wants to move forward and calls a client side function move
and then sends the server that the client wants to move forward.
Now the client has moved to position(10,0),
while the server is still at position(0,0)
. Now the server moves to position(10,0)
and sends an update to all clients.
But the client has now moved to position(20,0)
and now receives the position state from the server that the client should be at position(10,0)
.
What happens now? The client can't just apply the position from the server otherwise the client would jitter around.
One simple solution that I could think of would be a distance check.
if(Distance(position(10,0),position(20,0) > SomeNumber){
ForceUpdatePos();
}
But this is probably not a good idea because SomeNumber
depends on the MovementSpeed and latency.
I probably also would have to include a timestamp of the package because maybe the client has not heard back from the server for several ticks and then receives a bunch of unordered position updates.
What is a common technique to solve this problem?