Take the 2-minute tour ×
Arqade is a question and answer site for passionate videogamers on all platforms. It's 100% free, no registration required.

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 : gaming.stackexchange.com/questions/1239/what-is-a-hit-box –  rlb.usa Jul 9 '10 at 20:48
    
This is also related to "interp" –  Joe Philllips Jul 9 '10 at 23:27
add comment

2 Answers 2

up vote 16 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!) –  Lohoris 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
add comment

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
1  
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
1  
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
add comment

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.