Knockback in Networking

(2D Platformer)

When a player fires a bullet and the bullet hits another player it should cause knockback. The code works when it is not network related.

Host to Client: When the host fires a bullet and it hits the client it causes the client to get knocked back for one second and then the client’s character returns to its original position

Client to Host: When the client fires a bullet and it hits the host it causes the host to get knocked back a little bit, but doesn’t seem to apply the entire force. (I tested using high values for knockback)

Projectile Code:


Player Setup:
121843-playercomponents.png

ok so you need to do two things here.

First you need to decide who is going to detect the collision - host or client. Right now it just seems like both would be waiting for it and firing a Command. This is bad practice that can lead to confusion - only clients should be sending commands to the server, and the server should be sending RPCs to clients. It also may just cause subtle errors.

The other (main) part of this is that your NetworkTransform is local player authoritative. This means that if another player tries to affect this player, it won’t do much (in your case you see like it looks ok for a frame or two and then snaps back presumably when the next network packet comes in)

You need to have the server player send an RPC back to the affected player on collision so that they can apply the force to themselves.