I'm implementing client-side prediction. Most explanations assume the client sends messages like "Move my player up by 1 position". What if I send messages like "Set my player's velocity to x"?

explanatory graphic; showing sent messages and computed positions on the client and server over time

On the client, the player sets his own velocity (by client-side prediction) before the server does, resulting in the two getting out of sync. This problem persists even considering average latency.

How can I tackle this?


1 Answer 1


You should send redundant data, which here means send the position and the velocity. Even if you are out of sync, the fact that you have the position and the velocity allows you to correct the trajectory using an interpolation function.

Then using some tricks like delayed animations, accelerations, etc. allows to hide the latency.

Edit: I assume that the server is authoritative.

  • \$\begingroup\$ Thanks for your answer. Yes, the Server is authorative but even if i send redundant data with my velocity, the client could correct his errors but i often read things like "If the client/server use shared code for their entities, prediction errors will never really occure" but in my case, they will ALWAYS occure slightly which would cause stuttering all over. \$\endgroup\$
    – Blu3
    Oct 24, 2012 at 12:24
  • 1
    \$\begingroup\$ @user13842 the client will always get out of synch, you should correct the client side position and speed, like Thelvyn said, according to what server sends you. that way you don't get the stuttering movement unless your client is completely out of synch then you'll have to snap the values because correction would take way too much time. \$\endgroup\$
    – dreta
    Oct 24, 2012 at 12:45
  • \$\begingroup\$ This is the main reason to use an interpolation function. You cannot avoid latency, so you have to correct the movement in a smooth way. The client and the server simulate the world but the client have to listen to the server and perform corrections. Some techniques used in Source Engine networking : developer.valvesoftware.com/wiki/Source_Multiplayer_Networking \$\endgroup\$
    – Thelvyn
    Oct 24, 2012 at 12:49
  • \$\begingroup\$ it's briefly mentioned in this google talk too, it should get the idea across youtube.com/watch?v=Prkyd5n0P7k#t=18m47s \$\endgroup\$
    – dreta
    Oct 24, 2012 at 12:58
  • \$\begingroup\$ Ive found another solution for this particular problem. I add the time the client applied his input with each packet. Meaning #1 would have time:0 and the second time:100. Now the Server knows that the client pressed its button at time:100 and not before. \$\endgroup\$
    – Blu3
    Oct 24, 2012 at 22:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .