Hello guys,
in the past few weeks I read a ton of material about networking a multiplayer game, prediction, extrapolation,interpolation and whatever. I tried to implement my own solution to predict the movement of the player-controlled character and make sure it is validated by the server, but I have some jumpy movements that, as far as I understood, shouldn't be there.
What I'm doing right now is pretty simple: every client tick I record the state of the input, assign and incremental ID, and send it to the server. At the same time I simulate the client. When the server receives the command, it simulates it and send back to the client the new position together with the id of the just simulated command. Once the client receives the ACK packet, I assign the server position to the player, and then apply all the commands recorded, starting from the last acknowledged one. World state sync is done with a separate message at lower rate, and does not include the player position.
Simulation runs on both client at server at fixed 30fps for now.
When simulating variable (but still acceptable) latency, the player jumps around a little bit. Is it due to the fact that I should take into account the latency somehow when re-simulating the client commands when I receive the ACK packet?
I thought about two alternatives to solve the issue.
The first one is to set an acceptable distance between the client-side position and the acknowledged one: if we are in this range I keep the client where it is. The server will still be autoritative and all the collision and such will happen correctly, and the client won't notice any jumping around.
Or I could periodically send just the client position to the server, and validate the new position there using simple sweeping to check for collisions and such. As long as the movement is linear from point A to B, it should work fine?
Btw, the prototype I'm working on is something similar to realm of the mad god but with less bullets, just to give you and idea about what I am aiming for ;)
Thanks.