I'm having a little difficulty understanding how I implement Dead Reckoning in my Server-Client Winsock game.
I've been looking on the internet for a decent explanation that explains exactly:
When a message should be sent from the server to the client
How the client should act if it doesn't receive update messages, does it keep using the predicted position as the current position in order to calculate the new predicted position?
The Dead Reckoning method I am using is:
path vector = oldPosition - oldestPosition
delta time = oldTime - oldestTime
delta velocity = path vector / delta time
new delta time = current time / oldest time
new prediction = oldPosition + new delta time * delta velocity
Hope this is the correct formula to use! :)
Should also note the connection type is UDP and that the game is played only on the server. The server sents update messages to the client.
Can anyone help by answering my questions please?
Thanks
Dead reckoning requires a group of variables to function - called a kinematic state - typically containing position, velocity, acceleration, orientation, and angular velocity of a given object. You can choose to ignore orientation and angular velocity if you are only looking for the position. Post a comment if you are looking to predict orientation as well as position, and I'll update my answer.
A standard dead reckoning algorithm for networked games is shown here:
The above variables are described like so:
Pt: The estimated location. Output
PO: The most recent position update of the object
VO: The most recent velocity update of the object
AO: The most recent acceleration update of the object
T: The elapsed seconds between the current time and the timestamp of the last update - NOT the time the packet was received.
This can be used to move the object until an update is received from the server. Then, you have two kinematic states: the estimated position (the most recent output of the above algorithm), and the just received, actual position. Realistically blending these two states can be difficult.
One approach is to create a line, or even better, a curve such as Bézier splines Catmull-Rom splines and Hermite curves (a good list of other methods is here), between the two states while still projecting the old orientation into the future. So, continue using the old state until you get a new one - when the state you are blending into becomes the old state.
Another technique is to use projective velocity blending, which is the blending of two projections - last known state and current state - where the current rendered position is a blend of the last known and current velocity over a given time.
This web page, quoting the book "Game Engine Gems 2", is a gold mine for dead reckoning:
Believable Dead Reckoning for Networked Games
EDIT: All of the above is just for how the client should act when it doesn't get updates. As for "When a message should be sent from the server to the client", Valve says a good server should send out updates at approximately a 15 millisecond interval, about 66.6 per second.
Note: the "Valve says" link actually has some good networking tips on it as well, using Source Multiplayer Networking as the medium. Check it out if you've got time.
EDIT 2 (the code update!):
Here is how I would implement such an algorithm in a C++/DirectX environment:
Good luck, and uh, if you happen to make millions on the game, try and put me in the credits ;)