Bullet hit detection

Currently creating a single shot sheriff gun similar to like…, any murder game ever really. I know the ideal way to handle replicating the visual of the bullet would be something along these lines:

  • Client clicks → create the part to visualize the shot on their client (the one who clicked)
  • Send a remote event to the server
  • Server tells all other clients to replicate the same thing the original client did given the same mouse.Hit.p and origin
  • Other clients then use RemoteEvent.OnClientEvent to call the same function used to visualize the shot on the original client, thus displaying it on their screen

My question is now this: when do I check for the hit detection? When the original client’s part is made to show the shot do I also fire a Ray on the client? Then, if a part is hit (and has a Humanoid), call RemoteEvent:FireServer() to perform a sanity check and verify the hit was accurate (assuming a part was hit via the raycastResult)?

For context, currently to visualize the shot on the client I use the mouse.Hit.p and the origin to draw a part between those 2 points instead of a Ray. Should I switch over to a ray?

1 Like

Raycasting is pretty useful to create projectiles/guns. I myself use it.

You could use @TeamSwordphin’s raycast module, which is a very simple-to-use module that works with attachments.

1 Like

I used that very module to handle my knife hit detection, especially for stabbing. Although, in this case, it wouldn’t seem to prove useful as the bullets are going to be instantaneous.

1 Like

I see,

You can try using FastCastRedux, which is specialized in making gun or projectiles.

1 Like

do you want a delay on your hit detection when you specify when? which is commonly used for projectile bullets that can be seen moving, but in your case if the bullet is instantaneous like you mentioned then hit detection should be done right away.

1 Like

I meant moreso in my logic on when to do it. Do I have the server check for any humanoid hit for every bullet fired or only bullet’s fired that the client registered as a hit? I’m thinking the latter on this part.