Projectile client or server?

Hey there,

Quick question about projectiles. I was told that it’s best to handle velocities on clients as its smoother and less jittery. But the issue I am facing is understanding how to handle hitboxes if the hitbox is on server and velocity on client. The hitbox needs to be able to follow the projectile to apply damage/detect someone. How exactly does that work because as we speak it doesn’t. The hitbox is messing up the velocity if I weld it on server.

My initial idea → create the part on server → attach hitbox → fire to all clients and apply velocity on all clients.

2 Likes

You would be using a remote event that the client fires to the server when a hit is detected. This poses a pretty big problem with exploits though, since players could claim that their projectile hit someone it didn’t. You don’t have to add anti exploit measures if you’re just trying to learn though (and I honestly wouldn’t recommend it unless you’re already pretty experienced).

If you want to make it less exploit-prone, you’d need to implement a pretty complicated alternative:

  1. Use something more deterministic than roblox physics for your projectile. This is usually a raycast that inches forwards each frame, taking framerate into account.
  2. Tell the server when the client creates a projectile, giving it a projectile ID alongside the position of the player and where they were aiming. The server can do a distance check between the player’s current location on the server and the one being reported by the client to avoid players lying about their position.
  3. When a projectile hits a player on the client, the client tells the server who they hit alongside with the projectile ID.
  4. When the server sees a hit, it “recreates” the shot by using the position and aiming direction the client sent previously. It should also “rewind” the hit player’s hitbox since they will not be in the same location as when the client shot them unless they were standing still. Since you’re using a deterministic way to move the projectile you can instantly recreate the path the projectile took, and, if it hits the player’s rewound hitbox, that’s a valid hit.

Still doesn’t help against aimbots though, but that’s a separate vulnerability. If your projectiles aren’t going that fast then you don’t have to worry about that.

Yeah, while it’s u fortunate, but most people end up doing client side hit detection with server side confirmation for paranoia.

1 Like