Hitbox and Raycast Latency

I recently ran into the issue of delayed raycasts and hitboxes for my game.

Right now, I handle the gun logic like this.

Client: Sends to server the, origin, and mouse position → Server: Produces a raycast to see what would hit, usually the player would try to hit another player, fires allClient event → Client: receives and produces visual results

Now theres some issues and I ask for some advice on how to tackle this, often the player who shot will see the laser beam cross or even hit the player but considering latency, the server just wont see it that way.

Advice?

1 Like

For the client that shot, they should see the visuals instantly, no networking whatsoever. As for confirming the bullet actually hit their target, you could raycast on both(which is what many games with hit sounds and markers do). From the client, render the bullet, and complete the raycast, with a hit marker if necessary. You can tell the server as soon as they click the current barrel position and the direction. If you would prefer a better experience for laggy players and don’t care as much about hackers, you could potentially not do any raycasts from the server. Instead, track the reload speed, and how fast they are killing people.

2 Likes

Ill try this in a bit, thank you for the response