Collision and latency on a multiplayer coop-game (Should i fully trust the client ?)

Hi ! :grin:

I’m working on a coop game rogue lite, and i wonder if i should fully trust the client for collisions with enemies (and so, deal damage only when he got hit in local)

For what i found yet, people says to never trust the client for things like that (but what about a full coop game with no PvP ? :thinking:)

Because i have a problem right now, when experiencing latency (with setting up on editor settings “Average” emulation, and it get even worse with “Bad” emulation)) :

For example, i have an enemy that have an ability that make it roll fast to the player, and, on his attack/damage collision sphere overlap, it deal damage, stop movement (with an animation that make him get up), and then he can move normally to the player

But even with Average emulation, the client dont get it by the enemy, it stop before (because on the server, the player got it by the enemy)

That is really frustrating for the client (even if he dont lag that much (30-60ms and 1% packet loss), he’s lossing health without getting hit on his screen

So, is it a really bad idea to implement client side collision for damage dealing in my case ?

Because i dont see other solutions for this problem

Thanks for reading :slight_smile:

The technique you’re looking for is called lag compensation. (Read that whole article for the full explanation of how this works in Source, and pretty much every other server-authoritative, engine.

Here is an example implementation in Unreal:

I also recommend checking out some courses on Udemy, there are multiple that I’ve watched which cover how to do lag compensation, such as this one:

Additionally, there’s a new plugin I saw on the marketplace that’s on sale right now, although I don’t think it does the client-side prediction part that’s necessary to complete the puzzle:

RANT: Of course, you can always just decide to trust the client and use an anticheat. Doing server-authoritative networking has a lot of overhead in performance and development time, and even with the tightest server-authoritative networking when it comes to hit detection, players could still aimbot, triggerbot, spinbot, etc, and essentially completely ruin the game for other players even though they are “technically” playing by the rules according to what the server is verifying, i.e. they are correctly sending the server data saying “I am aiming at this guy’s head right now” when they shoot with an aimbot for instance. You do probably want to go fully server-authoritative when it comes to any kind of in game economy or inventory system, but with hit detection, it is perhaps not worth fully implementing a crazy high tech system like Valorant or CS:GO has for lag compensation with client-side prediction, because it solves a very limited subset of problems when it comes to cheating, and a holistic approach to anti-cheat is necessary to really stop people from ruining gameplay in competitive settings. In your case, since it’s co-op, there’s probably nothing wrong with just trusting the client.

2 Likes

To fully answer your question directly: I say who cares…trust the client! It’s not a competitive setting and in a co-op game you are, by definition, assuming the person you are playing with wants to actually cooperate with you! Just make sure things are reliably replicated and all the state does end up fully matching for both players. The other thing that server-authoritative networking offers is if a client glitches out, their state can be restored back to the correct one by the server. Although this is pretty unlikely it’s something to consider.

1 Like

Hello !

Firstly, thanks a lot for your answer and taking your time for me !

I checked the links you send me and it helped me a lot to understand the problem, and how could i correct it,

but the time i would put into this is maybe not worth it for my case (or maybe not that soon in my project), as you said my game is not competitive

So i’ll go for fully trust the client and see how it goes, thanks for your help ! :grin:

Hello ! :grin:

I searched about Lag Compensation, and, from what I understand, it’s for rewinding a collision test on the server by having the old positions of the client and his target

But I think what I need is the opposite, because the Enemy AI that rolls into the player, is controlled by the server and has no lag

To be more explicit, here is a screen from my prototype :

Now, I trust the client to handle Take Damage and inform the server that, locally, it got hit by the rolling Enemy.

(If I stop trusting the client, and let the server decide who take damage when overlap/hit happens, it’s going to be the invert situation, the client is going to be hit before he gets hit on his screen)

So, on the screen, the Enemy rolls fast to the player, but the player is walking in the opposite direction.
As you can see, on the Authority, the Enemy is already on it, but not at all on the client that have 30-60ms of lag and 1% packet loss

Are there any solutions about it ? I don’t think it could be Lag Compensation, but I can be wrong, i didn’t see people talking about this kind of case :sweat_smile:

Thanks a lot for your help !