📜 ⬆️ ⬇️

Multiplayer in fast games (Part IV: Headshots! Traveling in time)


  1. Parts I, II (single player with authoritarian server)
  2. Part III (The appearance of the enemy)
  3. Part IV (Headshot!)

How to hang the perfect headshots if you have a ping for 2 seconds? You will learn in this article.

The current algorithm of the multiplayer



This usually works fine, but it becomes a big problem for events that need high space-time accuracy. For example, if you want to smash the enemy head off !

Lag compensation


Here you have aimed your sniper rifle straight at your opponent's head. You exhale quietly pulled the trigger. You are confident in your abilities, you can not miss.

But you missed!
')
Why did this happen? How did this happen?

The fact is that in the architecture that we built, you aim at the place where the head of the enemy was 100 ms before the shot, not at the time when you shot!



It's like being a sniper in a world where the speed of light is insane, just negligible. You are aiming for an opponent, but by the time the light reached you, it was long gone in the old position.

Thank God, there is a fairly simple solution for this problem, which is also acceptable for other players most of the time (with one exception, which will be discussed later).

Here's how it works:

And everyone is happy!



The server is happy because it is a server. He is always happy, because he is always right.
The shooter is happy because he aimed at the enemy’s head and blew it with one accurate shot.
Killed - the only one who may be unhappy. If he stood on the spot at the moment of the shot, he himself is to blame. If he ran, then you are a good shooter.
But what if he ran across the danger zone, and a split second later he was shot dead when he thought he was safe? He will be distressed.



Here it can happen. This is a compromise we have to make. Since the shooter shot him in the past, a player may be shot after he has already hid behind a corner.

It sounds dishonest, but we will remember that from the point of view of the shooter this player ran across the square for as much time as he did from the point of view of the player. The only difference is the delay.

It would be much worse if the exact shot did not work!

We bring to the point of absurdity


It is important to note that this method works even with a giant ping.
Attention, the trick is done by professionals! Do not perform this trick on a production server! Teams with a two second prescription do not need to be executed in real life.



Conclusion


Such a thing as multiplayer is difficult to do right, but if you are armed with an understanding of the concepts described, there is nothing crazy in implementation.

Materials for further reading (English):
Gaffer On Games
Valve's latency compensation methods

From translator
This concludes the series of articles from Gabriel Gambetta .
But I'm not saying goodbye to you. I'm still going to write an article about how to build a serialization of the game world, and in general you never know where research of such an interesting topic as multiplayer will lead you!

UPD


krimtsev asked a very reasonable question.
FPS and PING understand how to influence this, but what do you think about the TICKRATE account?

I answer. With bogotoff, we allowed ourselves to deviate from the described algorithm, since it seemed inconvenient for us to play at a server refresh rate 10 times per second.

Since we use interpolation on the client to display the positions of enemies, it would not be entirely correct to apply a specific server state that the client allegedly painted, because in fact the player was shooting at an enemy that was between two different states.
Since we use the lag compensation mechanism, it can be used to find two states of the world between which a shot occurred and interpolate them.
Thus, you can adequately shoot even with one server update per second:



Although the game at this server frequency, of course, looks awful. Do not do this. In general, keep the FPS as high as possible. The higher the sampling rate of the game world, the better the gaming experience the player will have. Although my personal IMHO that above 60 - no longer makes sense.

Source: https://habr.com/ru/post/303006/


All Articles