Download

Instant response from enemies on a client

Hi,

I am working on a coop-based game that involves very fast-paced fights against multiple enemies together with a team mate. One behavior I want to implement is that enemies are being knocked back when hit. Since the fast pacing I would prefer that knockback to happen instantaneously rather than with server delay. Specifically, I want to achieve the following behavior:
Assume that enemy A focused on player 1 and enemy B focuses on player 2. In this scenario I want enemy A to be calculated on player 1’s machine and be replicated to player 2’s machine and the other way around for enemy B. This way each player gets instantaneous response (e.g. in the form of knockback) from the enemies that are focusing him.

I am aware of the fact that UE only replicates from server to client. However, player characters are actually replicated from the respective client to the server (if I’m not mistaken). I wanted to make use of this exception by having the player controller posses the enemies that are focusing the player but I realized that each player can posses only 1 pawn. Am I missing something or is this an arbitrary constraint that effectively only 1 pawn (the player pawn) can be replicated from client to server?

Thanks for taking your time thinking about this (oddly specific) topic!

Hi,

it always works the same, the player character is no exception. With the character movement it instantly response to the client input (so that you get no lag), and sends the client input to the server -> server does its own simulation -> sends result to client -> client applies server correction (smoothly over a short time, unless the difference between server and client position is beyond a certain threshold, then it snaps to the server position). So it is still server authoritative but instantly response to client input.

If you want the client to tell the server something, you use a “RunOnServer” RPC (RemoteProcedureCall, client asking the server to execute that event locally on the server).
[HR][/HR]
So generally, if you want instant response on the client, then you execute it locally on that client, instead of waiting for the server. Of course the AI controller only exists on the server, therefore the knock back instantly executed on the client will have no influence on the AI behavior.

Thanks for your reply!

When I simulate a network delay of e.g. 1000ms from client to server and then move on my client, the server just lags 1 second behind. On my client there is no correction going on even though the simulated position of the client character that is being replicated from server to client lags behind.

Furthermore, is it correct that it is only possible to have 1 pawn per client that has this kind of behaviour where the client-local pawn is ahead of the server-side pawn? This seems like an arbitrary limitation to me.

What was done was executing the logic instantly locally on the client while also sending it to the server. Nothing prevents you from doing that in your own player input logic. You can take a look at point 1 to 9 under “Movement Replication Summary” here Character Movement Component | Unreal Engine Documentation to get an overview of how it was done for the character movement component.

It makes sense for the player input, since the client will know about that before the server does. So there you generally don’t want to wait for the server. If the client knows about the knock back before the server does, then you can also locally instantly start the knock back animation. But at this point the server logic will continue as if the knock back didn’t happen. It will only change once the server knows the knock back has happened.

So keep in mind that this instant response on the client does not influence the servers logic at the time where you see it on the client. Only once the server knows about that (receives the RPC from the client). Also keep in mind that all AI controller (and therefore behavior trees) only exist on the server, but do not exist on the clients. So the logic of those is all server side.
[HR][/HR]
And I don’t know how to properly build a fast paced combat system that should also works with multiplayer. But I would guess that you need to build the AI in a way that allows the client to know about its moves beforehand to eliminate the network lag there, visually instant response for the client on player input, and effects and faking whatever you can to bridge the time between player input and when the server knows about that and adjust its simulation.