3
\$\begingroup\$

I've spent some time now messing around and just trying to learn dead reckoning and client side prediction for the fun of it. Most of what I do doesn't need it, so i've never had a need to go down the path.

I get how to predict the client and i've got a completely deterministic setup with a lockstep of 60fps for the physics on client and server. Both client and server use the same movement code, and i'm using constant velocity to reduce complexity. I also understand how to interpolate for corrections. I also have the server and client ticking at nearly the same time (as close as one can really get it).

The problem i'm having, that doesn't seem clear to me in anything I've read (i'll put links at the end to a few things), is what does the client message sync against on the server? So, for example, the client is at 0, 0, 0, with a heading of 0, 0, 1 at tick 0. At tick 5 the client presses the button to start moving forward at 40u/s and sends the message to the server. We'll say that the trip to the server takes 50ms and 50ms back. So the server gets the message at tick 8 (roughly), and here is where I am slightly lost.

The client sent the tick they pressed the button along with the position and new velocity. Does the server do:

  • A. Look back at tick 5 and say "you're good b/c you were where you should be at that tick"
  • B. Check against tick 8 and say "well you where at 0, 0, 0 at tick 8, so you didn't start moving until then".

It would seem with B, which is what i'm currently doing, that the server is always sending back a correction. B also has a bad side affect that when I stop, I'm almost never where the server is and the interpolation of this feels impossible to get right.

While with A, it would seem I have to redo all collisions for that object from tick 5 thru 8 on the server, but this sends less corrections and would give a smoother feel. I understand that A is used for lag compensation when firing a weapon or taking some action that would affect other entities, but is that also used for motion?

Things I've read: http://gafferongames.com/ http://www.gabrielgambetta.com/fpm1.html Various articles out of books and other websites that seem to skip past this detail

Thanks in advance for any help.

\$\endgroup\$
2
  • \$\begingroup\$ Here is one article that could be useful for you : developer.valvesoftware.com/wiki/Source_Multiplayer_Networking \$\endgroup\$
    – tigrou
    Commented Jan 28, 2014 at 13:21
  • \$\begingroup\$ Thanks, I've actually read that several times too just couldn't remember the link. It's a good source for a high level over view but i'm looking for a specific detail that it doesn't cover in depth. \$\endgroup\$
    – wolftousen
    Commented Jan 28, 2014 at 16:32

1 Answer 1

5
\$\begingroup\$

That's "server reconciliation", I've written specifically about it here: http://www.gabrielgambetta.com/fpm2.html Since you link to one of these articles in your question, I assume you've read it already. Believe me, the answer is there :)

It's more like your option "A". Typically what happens is that you get a server update for a "true" state of the world sometime in the past. It will generally match what you had predicted for that instant in time, unless you ran into another player or something.

The key here is to predict the current state again by interpolating from whatever the server was the true state and the inputs the server hasn't seen yet. If both the client and the server agree on what happened at T - dT (and they must since the server is authoritative), and then apply the same inputs again (the server is already processing them, and the client keeps them until a future server update has a timestamp in the future respect to when the input ended), they must end up with identical states.

In my article, this is explained with pretty diagrams; the problem is stated in Synchronization issues, and the solution (which I outlined above) in Server reconciliation. Let me know if you still have doubts :)

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for responding, kind of unexpected to get the author of the article lol. Your's by far is the best I've read on the subject. If probably read it 10 or more times now, but just keep missing it i guess. So if i were moving straight already, and then changed my orientation. The server would think I was going straight longer than the client did. When the server gets the message, does the server check against it's current server position (which is farther forward than the client and will cause a correction) or the past server position that matches the timestamp/tick? \$\endgroup\$
    – wolftousen
    Commented Jan 28, 2014 at 16:30
  • 1
    \$\begingroup\$ The server would think I was going straight longer than the client did - no, why would it? The inputs you send have timestamps, so if you have been pressing the "right" key for 20ms since you sent the last input, you send "moving right for 20ms". The server never interpolates; it only gets real, actual inputs and applies them to the deterministic world. It's the client who does funky stuff. Maybe here's where your confusion comes from? \$\endgroup\$
    – ggambetta
    Commented Jan 28, 2014 at 16:45
  • \$\begingroup\$ Ok, yeah i think that's where i was getting hung up and not using the client timestamps the right way. I'll experiment some more and see if I can't get it working the correct way. Thanks! \$\endgroup\$
    – wolftousen
    Commented Jan 28, 2014 at 17:22
  • 3
    \$\begingroup\$ @wolftousen FYI, your question inspired me to write a new Sample Code and Live Demo page, check it out! \$\endgroup\$
    – ggambetta
    Commented Jan 30, 2014 at 14:40

You must log in to answer this question.

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