Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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.

share|improve this answer
    
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. –  Blu3 Oct 24 '12 at 12:24
1  
@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. –  dreta Oct 24 '12 at 12:45
    
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 –  Thelvyn Oct 24 '12 at 12:49
    
it's briefly mentioned in this google talk too, it should get the idea across youtube.com/watch?v=Prkyd5n0P7k#t=18m47s –  dreta Oct 24 '12 at 12:58
    
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. –  Blu3 Oct 24 '12 at 22:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.