Мультиплеер туториал 1: основы

  • 6 favourites





46,199 visits, 69,922 views



This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Lag compensation

Consider the following problem: player A is standing still and aiming at player B, who is running to the right. Player A hovers the mouse exactly over player B and shoots. (Assume the shot is instant-hit, like a laser or infinite speed projectile.) The message to the host indicating they are shooting takes 100ms to get there. During that time, player B keeps moving to the right. The host receives the message 100ms late and tests for a collision where player A is aiming - but they miss, because player B has moved on! Player A saw themselves give a direct hit, but they never caused any damage.

In general, the host sees each player do everything a bit late because of their latency, and players end up missing moving targets. This kind of issue will infuriate players, who eventually learn that they actually need to aim for the empty space ahead of where the player is moving. This is not very realistic or fair. Lag compensation is a technique to avoid this result.

Rewinding time

The host knows how far behind each player is seeing the game, because it is measuring everyone's latency. So when the host receives the message indicating player A is shooting, it knows they actually did that 100ms ago.

The host is remembering the past few seconds of each object's history. It can then look back and see where player B was 100ms ago. Then it can test if player A scored a hit on player B at the time they originally fired. This is how the latency of player A is compensated for by the host, and it means player A likely scores a hit on the host when they see themselves score a hit on their own screen.

This creates another problem though. Player B is on a delay as well. If they have a 100ms latency, then the host is moving them about 100ms behind where they see themselves (remember their local input prediction moves them straight away). On top of that, the host is moving them further behind when testing for a collision when player A fires.

This means player B sees player A aiming behind them where they would miss, firing, and then they get hit anyway! In extreme cases player B may have in fact reached shelter from player A so they can't be directly hit, and then they suddenly take damage. This is annoying for player B, but is usually not as bad as having no compensation - at least players actually have to aim directly at each other to hit. A common solution is to not clearly indicate where players are aiming, so player B can't easily see player A appears to be aiming behind them, making it look more acceptable when they are hit.


  • Order by
Want to leave a comment? Login or Register an account!