How would I detect when a raycast has passed by a player?

I would like to play a sound when a raycast passes by a player.
How would I do this?

1 Like

I’m guessing you want something like a bullet or something passes by?
How about 5 raycasts. 1 for the bullet (in the center) and 4 offset but parallel around where the bullet is. If one of the 4 hits the player and the bullet doesn’t then play the sound at the player.
Maybe load the sound into the player’s HumanoidRootPart then play it so it makes the sound at the player’s location.

You could find the distance between the player and the raycast and if its closer than a certain amount, you know the shot came close to the player. Using a line segment to point distance for a quick approximation for this which be close enough and should be fairly quick as far as performance.

1 Like