When you are taking part in a shooting game in the real world, there is no lag. You can target a moving object and shoot it with precision. In case you missed it, the fault lies in your skill and not in the gun or the environment. But, the situation is not the same in a virtual world. When you are playing FPS or First Person Shooter games online, the simulation is real but not always perfectly accurate. Such games demand very fast reflexes and perfect accuracy. But to ensure that there is no lag in the virtual world is a tough task. What you see in the virtual world will always have a certain amount of lag. So, the target you see on the monitor may well be some more steps ahead of where he is standing at that moment. But, this is not to suggest that there are no ways to resolve this lag. If there were no techniques for lag compensation, there would be no thrill and fun playing such games.
What Is Lag Compensation and Why Is It Necessary?
One needs to understand how networking communications work. This refers to the time an information packet takes to go from the client to the server and back again to that client. Lag refers to the delays which happen between the player’s action, such as shooting or dodging the bullet, and the time when he receives the server’s reaction like shooting the bullet or avoiding the hit.
Lag can be calculated in terms of milliseconds and can differ when servers are located in different areas. So, when you play on servers which are residing in your own nation, the lag is less but when you play games on servers located in other countries, this time may be much greater. Lag not only depends upon the distance of the servers; it is also dependent on server capacity and web connections. The ideal scenario would be to play on a LAN because here, latency is almost non-existent.
When servers are based on places outside your own country, the lag can be very lengthy. Sometimes, the lag may be of hundreds of milliseconds. For games like the First Person Shooter games, this can be very dangerous. So, the idea is to make sure that the lag is controlled and techniques adopted for lag compensation.
The best way to compensate the lag is for the server to calculate the average client latency. It then “rewinds” the time back to find out whether the individual had been aiming correctly at the point where the image would be visible to him. This method involves multiple variables, such as server tick rates. This will calculate speeds at which game servers carry out updates per second. For the intervals, the server will use another technique called interpolation to track the actual trajectory of information. Human reflexes are such that 128 or 64 refreshes in a second are good enough for most cases. So, lag compensation basically refers to techniques which grow from the need to deal with problems in server communications. It seeks to lessen the difference in the time taken for responses so that your game playing experience is smooth. You can apply these techniques both at the server client levels depending on what kind of game you have developed and the type of feedback you want to send to players.
On the client side, it is possible to work with interpolation systems. So, the simulation on the client side will be some steps behind server simulation. This means that when information from the server is got, the client-side simulation will not get updated right away. You may even use extrapolation to make the client predict where the characters will be positioned next to and then rectify these positions once it gets data from the server side. These solutions on the client side may not be effective when you have multiplayer games. This is when you have to choose lag compensation techniques from the server side.
One of these methods is a deterministic simulation where all simulations take place on the server. These are based on user inputs which clients will send to servers. So, you can get similar lag on all your clients and you can lessen compensation problems. This method is suited for games which do not need quick responses. Alternately, you can use a reliable TCP (Communication Protocol) to guarantee reliable data packet delivery. Here, messages are received by TCP always and this makes the processing simpler for the server and client. This is good for games which have a handful of players in one room. Finally, there is a third technique where you share the total state of a game. So, only one client can be changing the state of the game at a time. You can guarantee thereby that every server and client has the most recent and valid game version.
Also, read: http://www.newspeakblog.com/scope-browser-online-gaming-future/