This post will be highlighting lag in video games, its effect on the online experience, as well as prevalent lag compensation techniques being used in the game industry today. Lag is inevitable in any online gaming experience. It can be the cause of many game bugs and inconsistencies, player frustration, and more. Unfortunately, many lag-inducing factors are completely out of the control of the developer. To cope with this reality, game developers have been able to obscure the symptoms of lag through various techniques that have been developed over the years.
Generally, online games will have a server dedicated to the simulation of the game world. Clients share their inputs and other relevant information to the server, which takes that data to update the simulation state, and finally, sends the updated information back to the client. This is your general Client-Server Architecture utilized by most video games.
Unfortunately, packets can only move as fast as its connections allow for it to. The time delay between a player’s inputs and when they receive a reaction from the simulation is what is known as lag. If you were playing a game of online chess, it may be acceptable for inputs to be delayed a few seconds as gameplay will be generally unaffected. However, consider the fighting game Street Fighter. This game features combos that require intricate timing, and players have spent hours practicing in order to perfect these combos. Any change in the timing will greatly affect their ability to perform their combos, and in turn, their enjoyability of the game.
A typical scenario in a client-server model. The client sends information over to the server (green), and receives a response 100ms later (red), causing an input delay of 100ms. [Image Source]
There are two main causes of lag – inadequate hardware, and network performance.
If your hardware is not powerful enough to sufficiently power the simulation, then your game will lag since it wont be able to keep up. Luckily, this is relatively simple to manage, as you simply have to upgrade your hardware to compensate for the lack of processing power.
The main problem concerning lag is the network. Even in an ideal scenario where the network is functioning perfectly (sufficient bandwidth and no congestion), data transmission and the distance that data must travel still plays a significant role in latency. The time it takes for data to travel from the client to the server and back again is known as the ping. The higher your ping is, the longer it will take for the game to react to your inputs. Of course, the closer the server is to the client, the lower your ping will be.
Game companies are generally pretty good at optimizing server location and routing to cover their player base, but there will always be outliers. Although this lag is inevitable, developers have established techniques that “hide” the effects of lag on gameplay.
As I mentioned earlier, input delay occurs because the client needs to wait for information to return from the server which is running the simulation. One of the more common techniques game developers use in order to decrease this delay is to run a client-side simulation of the game alongside the server simulation. Rather than wait for the server to return information on the game world, the client utilizes prediction techniques to update its own simulation. When the client receives the update from the server, corrections are made locally to account for differences between the prediction and the actual simulation. This technique does not increase input responsiveness at all; the input data will still need to travel to the server. Instead, it simply gives the client a false sense of responsiveness.
Client-side prediction working as intended. [Image Source]
Client-side prediction techniques do have a serious drawback -- how do we correct for this desynchronization between the client and server simulations? The easiest way would be to simply force all the correct information onto the client simulation (snapping); however, this would lead to objects teleporting all over the place on their display. Another common method you will see in video games is some sort of interpolation/smoothing algorithm. This causes the "rubber banding" effect most online gamers are familiar with. Although not ideal, it is still an improvement.
There is another concerning issue -- the simulation running on the server continues to run while packets are travelling. Consider the scenario where a player in a first-person shooter game fires a bullet at t=10. If the server receives the "fire" packet at t=11, then it will be updating its simulation with outdated information. While what the player saw was a direct headshot at t=10, the enemy may have moved by t=11, causing the simulation to believe that the player had fired their gun too late.
Luckily, the solution to this problem is simple; the server simply needs to keep a history of its simulation. Using this history and the ping of the client, the server can effectively "go back in time" to process the packet data at the time that it was sent at. Now, the simulation will react correctly, and the player will have killed the enemy.
Finding effective ways to deal with lag is extremely important for any online game. Being an avid online gamer, I have experience first-hand how lag can single-handedly destroy your enjoyment of a game. Unfortunately, not much can be done about it until solutions to slow packet speed and network congestion are found. Above, I have outlined some of the techniques being used today to obfuscate the effects of lag on gameplay. Although these techinques have proven to be adequately effective, it is quite clear that they still have a ways to go.