Touched event only firing when part is in contact with player

I have a projectile that is moving rapidly through the workspace. As you can see here, the projectile is set up to stop on a touched event. It does when the projectile hits a player:
https://i.gyazo.com/613ccc34ea8cf71f365aeac62653279c.gif
(Ignore the red line)

When the player is out of the way, the projectile flies straight through, meaning that the touched event is not firing. The output was also empty when flying through while the output printed “HIT” when it stopped.

Is this the intended behaviour? I don’t think it is because the wiki gives a code tutorial to get the number of parts another part is touching.

https://developer.roblox.com/api-reference/event/BasePart/Touched

Any help appreciated!

I have run into this many times when using touched for things like this. Your best bet is to not rely on it at all. Instead, use raycasting. It’s far more accurate.

Or, if you want this to be dynamic, you could make a Region3 around the part and see if anything gets in it. If it does, stop moving. You’d have to put that in a loop or something to get it to work.

2 Likes

When you say raycasting, how do you mean?
Fire a ray infront of the bullet by a stud or so and if it returns a hit, stop?
Wouldn’t that create a lot of lag due to the amount of Rays being created?

No. Raycasts are well optimized. I’ve fired hundreds per frame before with zero noticable performance dip.

4 Likes

That’s what I meant :slight_smile:

1 Like

Ok I will use this. Thanks!

@Kampfkarren thanks for the clarification

:smile::smile:

1 Like