Arqade is a question and answer site for passionate videogamers on all platforms. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Specifically in regard to online games, what is lag compensation? Should it affect the way I play?

share|improve this question
Also see Hit Boxes : – rlb.usa Jul 9 '10 at 20:48
This is also related to "interp" – Joe Philllips Jul 9 '10 at 23:27
up vote 17 down vote accepted

Valve published an excellent article explaining the multiplayer network details (also called "netcode") of their multiplayer games. From this article:

Lag compensation

Let's say a player shoots at a target at client time 10.5. The firing information is packed into a user command and sent to the server. While the packet is on its way through the network, the server continues to simulate the world, and the target might have moved to a different position. The user command arrives at server time 10.6 and the server wouldn't detect the hit, even though the player has aimed exactly at the target. This error is corrected by the server-side lag compensation.

The lag compensation system keeps a history of all recent player positions for one second. If a user command is executed, the server estimates at what time the command was created as follows:

      Command      Current      Packet          Client
     Execution  =  Server   -  Round-Trip  -     View
       Time         Time         Time        Interpolation

Then the server moves all other players - only players - back to where they were at the command execution time. The user command is executed and the hit is detected correctly. After the user command has been processed, the players revert to their original positions.

This screenshot was taken on a listen server with 200 milliseconds of lag (using net_fakelag), right after the server confirmed the hit. The red hitbox shows the target position on the client where it was 100 milliseconds ago. Since then, the target continued to move to the left while the user command was travelling to the server. After the user command arrived, the server restored the target position (blue hitbox) based on the estimated command execution time. The server traces the shot and confirms the hit (the client sees blood effects).

There's more information in the article. If you're interested in this, I highly recommend reading the whole thing. It's not too long, and among other things it also explains entity interpolation (which is a part of the above equation) and input prediction. Keep in mind Valve is responsible for the netcode behind some of the most popular online games today - Counter Strike and Team Fortress 2 - so this is probably as professional as it gets.

The source code implementing this is publicly available as part of the Source SDK.

share|improve this answer
+1 excellent article (and very famous one, a must-read!) – o0'. May 14 '11 at 21:19
It's amazing how there is almost no audience for lag switching in Valve games.. yet, in every series of Call of Duty, lag switching is almost a normal annoyance. – Earlz May 18 '11 at 0:41
+1, though, could you please copy the relevant passage into your post? – BlueRaja - Danny Pflughoeft Jul 20 '11 at 5:06
@BlueRaja done. – Oak Jul 27 '11 at 6:45

Lag compensation is a feature of modern games that allows the engine to estimate where players would be, based on their ping.

For example, if a user is running forward at 10 feet per second, and their ping is 1000ms, you will see them continue to run forward for that whole second or until you receive another update of their position and direction.

This prevents users from looking like they are jittering around. However, in cases of extreme lag, "rubber banding" can occur.

share|improve this answer
The one thing I've learned in playing lag compensated games is to never lead my shots like in older games. – Jeffrey Jul 9 '10 at 20:38
Valve's article disagrees on that definition. What you describe sounds more like the "entity interpolation" aspect. – Oak Oct 31 '10 at 19:16
This answer is incorrect; lag compensation is a feature of the server, not the client. @Oak is also incorrect; what this answer describes is called extrapolation, not interpolation (they are closely related, but the difference is important to a game programmer) – BlueRaja - Danny Pflughoeft Jul 20 '11 at 5:07
@BlueRaja: Lag compensation HAS to take place on BOTH the client and the server. On the client, you need to be able to deal with server latency, and vice versa on the server. – John Gietzen Jul 20 '11 at 19:02
@JohnGietzen I can see why it helps on the server, but lag compensation on the client will only result in estimating a state with dubious reliability. Better to just let the client play on the lagged data and compensate for that when their actions get back to the server. Then, at least, the client's view of the world is consistent with a real (recent) point in time, not some wild-ass guess that the server would have to either trust/recalculate before being able to lag compensate itself... – Basic Mar 7 at 20:55

Your Answer


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.