.Touched not firing in time

Im trying to make a flying projectile using body velocity

However when i shoot the projectile the position seems to be through the player rather than where the object actually hit

Im thinking about constantly recasting ahead of the object and detecting how close the projectile is from hitting the object but i feel like that would be a bit laggy

Please let me know on anything thanks! :slight_smile:

2 Likes

Usually people use raycasts for projectile detection because .Touched doesn’t really work (as you’ve noticed)

How should i use the raycasting, or is my idea bang on?

What do you mean recasting ahead of the object?

raycasting in the direction the object is heading to see where it is going to hit and then get the distance and see if its hit it

2 Likes

There is a raycast module that will follow anything, you can use this raycast module for the hitbox and it will work very easily. Here is the module :

1 Like

Yes do this

wouldnt that be a bit laggy?
character limit

This really depends on the projectile, if its a bullet then a raycast is perfect since bullets are often thin and are considered 2 dimensonal, however say your making a giant fireball rays would not be optimal here since that would require drawing an arbitrary number of points each one representing a ray not only is this inaccurate but also inefficient. To solve the fireball example there a couple solutions, easiest ones are using something like GetTouchingParts() or the new region3 system that roblox implemented, More optimal solutions would be doing something like Separating Axis Therom which I believe works for any convex geometry although coding this optimally is significantly harder, so I recommend using the first 2 solutions

1 Like

No it wouldn’t. Rays are really really efficient at short ranges (which is what you’re going to be doing). Its also a way more reliable method to check if the bullet hit something.

i will keep that in mind however the GetTouchingParts() method is way easier, Thanks

Its also unreliable and the bullet can go through the player without hitting them

I’ve gone to insane yet acceptable speeds and it hits every time, just slightly more off

With 50 player servers, you will get different results.