Client Prediction
From AntiHax
Client prediction is a client side technique used by first person shooters and other multiplayer games where network latency would cause delays in local player movements.
In the input handling, the client takes the input from the mouse and keyboard packs it into a usercmd and sends it to the server to be processed. Since the server is authoritative in regards to the movements and positions of all the clients, the server must tell the client where they should be. Since there can be a delay of 10 to 250 ms to send this information to the server and for it to respond with the updated position, this is a serious problem.
To solve this problem, the client processes the usercmd and stores it in an ordered list then sends it to the server. (Note: HalfLife actually sends 1 + cl_cmdbackup usercmds at the cl_cmdrate rate to counter packet loss)
The server processes the usercmd and will periodically send the local client his position on the server along with the last cmd id number. When the client receives this update, it physically moves the local player back to this position and then reprocesses all the usercmds since the one the server last executed. In theory the local player should now be in exactly the same position it was in before the update. If not, a prediction error occurred typically due to packet loss or inconsistent world/player states or worse such as an inconsistency between the client and server physics.
Prediction errors are quite obvious and typically result in the local player warping around. Error smoothing is a simple technique which will smooth the error over a specific amount of frames and helps reduce the effect of a small error.
