Lag compensation in precise melee combat

The melee combat system for my game has something called “deflecting,” basically blocking right as an attack hits you (like Sekiro). It works by starting a short timer when a player blocks, If the player is hit by an attack while the timer is not 0, the attack is deflected. Hits are detected by the client of the attacking player and then verified on the server. I need players to be able to see an attack coming and deflect it based on reaction, but the animations replicate a little too late, so I plan to account for lag by doing this:

  • store the ping of every player in the game, update every 10 seconds or so
  • when a player attacks another player, use their combined ping to start a timer
  • when the timer reaches 0, check if the attacked player is deflecting.

This should make it so the player being attacked will see the animation as matching up with the deflect timing, since the animation takes time to play for everyone else in the game due to lag. I’m not entirely sure if this will work, so I need some feedback on this. Is there some variable I’m missing here?

2 Likes

Your effort towards trying to fix this issue is smart and commendable, but ping ends up being difficult to use in practice. I recently wrote about the pros and cons is using ping in a similar fashion here: Good ideas to combat exploiting - #5 by Icee444

I’ll take out the important details posted there and put them here. The main issues with ping are that:

  1. Ping can quickly spike and dip
  2. Players can also boost their ping (add latency) with external software by delaying sending back a response. But that does not necessarily mean it takes longer to receive the information. This would give the player a huge reaction time advantage.

Because of this, there is no way to make this 100% fair to all players without being able to trust the client. So, I would suggest adding a significant delay, (maybe 0.5 seconds), and depending on the player, they would have more or less reaction time. I realize this doesn’t really help you out too much, but I would rather see a game be not exploitable as opposed to laggy.

If anyone else has any comments/suggestions on a better method, please add those.

1 Like

What popular AAA-games are doing (I know for a fact that Overwatch does this) is to not actually compensate players for their poor connections but to instead move the world on the client “ahead” based on their ping and just replicate the player’s input based on a synchronized clock.

For example, let’s say you have Client1 moving a character with a ping of 100ms and Client2 with a ping of 150ms.
If you were to put both clients and the server next to each other the character and world of Client1 would be roughly 50ms (plus some extra to account for jitter) ahead of what the server sees whereas Client2 would be roughly 75ms ahead.
The Clients would then just replicate their player inputs to the server to verify which in turn replicates the results back to the clients.

For example, when Client1 decides to jump with his character the Client replicates the jump command together with a timestamp to the server which then checks if the input is valid.
Since the server is in the past relativly speaking it would wait according to the timestamp sent by the Client to check if the player input is still valid (e.g is the player still alive at that point in time?) and if it is replicate the command together with the timestamp back to the clients.
Client2 would then “replay” the jump of Client1 (“Where would the character be if it had jumped at that point in time?”) or Client1 would have to move his character to where it would be if he had never jumped in the first place if the server deemed the jump to be invalid.

5 Likes