Hitbox Detection

I would use Raycasting, and simply do multiple casts depending on the shape and size. Any other method is going to fail in reliability or be slow.

Definitely don’t use Touched, GetTouchingParts or anything that relies on the projectile being in a certain position at a certain frame - lag could cause the projectile to skip right past an object in a single step.

If your projectile is cylindrical, consider how many points are needed to represent it reasonably well. If it’s relatively small, a single Raycast will generally suffice. If it’s very large, 8, 12, 24 perhaps. You could create an algorithm to decide how many casts to do based on the size of the projectile, and then using some trigonometry place their origin around the circumference.

If your projectile is cuboid, Raycast at the four corners and then again based on size decide if it’s necessary to do interim casts along each straight edge.

In many cases, this will still be quicker than Region3 and with appropriate CollisionGroup or whitelist filtering, you can help to reduce the overhead further.

10 Likes