Locally-Replicated Projectile Hit Detection

For my game, I already have everything done to properly replicate projectiles.
However, on other clients, I need an efficient solution for detecting if/when a projectile will collide with something (to delete the projectile).

Some of my projectiles are affected by a gravity factor, so I cannot just use a single raycast to detect when a projectile will hit something. Additionally, each projectile’s position is calculated every frame, so raycasting each “step” of the trajectory of a projectile would not be performant.

Does anyone have any ideas for an efficient solution?

EDIT:
On each client, they are already handling their projectiles with a combination of raycasting to the next step (and detecting hits), and lerping the projectile “along” the ray.
My problem comes in with replicating the projectiles with other clients.
I would assume that raycasting for each step of every gravity-affected projectile would be quite intensive, so I don’t know if that would be more efficient than hooking up a .Touched event for hundreds of projectiles at a time.

Would using .Touched for gravity-affected projectiles be better than raycasting each step of the trajectory?

Try it. If it works, then there’s your solution

I’m looking for the most efficient solution, I already know working solutions.

Are you using BodyMovers for your projectiles?

I’m not sure if you seen this Thread but it’s relevant.

Using Touched Event should be fine.

Another way you could do it is use the method :GetTouchingParts() on the projectile and loop through it to see a valid collider, not very efficient, but its a suggestion :smile:

No, I’m using Vector3s/CFrames

Thanks for the reply, but I already know how to model the motion, I just need to know an efficient way to handle collisions for possibly hundreds of projectiles at a time. (A less detailed collision handler though, as each client would be handling every projectile. Each client is already handling their own projectile collisions with raycasts, but I would assume that raycasting for every player’s projectiles could be quite intensive)

At least you bothered to reply. :slightly_smiling_face:

In my opinion there’s no real reason to not use velocities for this. Now, the projectile itself should represent the bullet but shouldn’t BE the bullet when you use CFrames, I’d recommend using raycasting for this, now you should be able to find the posts about raycasting projectiles.

CFrame doesn’t follow any type of hit detection, and doing magntide or region checks would be extremely inefficient for this if you think about the amount of projectiles you’ll have and etc…

First one I found is this: Weird Projectile Raycasting Behavior Don’t know if any of it works and etc… but is worth getting an idea from the GIF alone.

I am using raycasting. Maybe I worded the problem wrongly.

On each client, they are already handling their projectiles with a combination of raycasting to the next step, and lerping the projectile “along” the ray.
My problem comes in with replicating the projectiles with other clients.
I would assume that raycasting for each step of every gravity-affected projectile would be quite intensive, so I don’t know if that would be more efficient than hooking up a .Touched event for hundreds of projectiles at a time.

You only need the accurate hits on the client firing the gun and the actual bullet. Now on the other clients it’s far easier to just use velocities and calculate it to match the current bullets trajectory and use the .Touched event.

Similar to: Modeling a projectile's motion You might be able to do this on the server for when the hit goes through to get a “range” of where the bullet should be to verify the hit. Just a thought no clue how it’d end up.

1 Like

Alright, thanks. Now I realize the main question could’ve just been simplified to “are using a lot of rays better than using a lot of .Touched events?”

To your edit: For hit verification, I could give the server a timeElapsed parameter to get the position of the projectile at that time (and just check the distance between the thing being hit with the projected projectile position). I am not sure if I will actually use accurate hit verification, namely, following the projectile along its path to detect if any walls are in the way.