Projectile movement

Projectile movement

Hi,
I'm using raycasting for my smaller projectiles. The only problem with this that sometimes it goes trough moving objects. I am pretty sure it is because the moving body (npc) goes where the start point of the projectile is going to be for the next step, and the raycast does not report out-of-body hits.
Is there a workaround to get the internal hit? I'm thinking of change it to shapecasting with phantoms, but i will get the same 'tuneling' effect, i think.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
havokmax's picture
Best Reply

Hi,

To make sure I understand, it sounds like the problem is that you do the raycast and don't hit anything, then when you step physics a body moves so that it contains the new position of the projectile from which a ray will be cast in the next frame. In that case the next frame's raycast will indeed miss because it begins from inside the body. You could fix this by raycasting in both directions. Another option would be to use hkpWorld::linearCast, which can detect collisions with an object even if it starts from inside.

Note that it's still possible to get incorrect misses, for example if the body and the projectile cross each other in the middle of a step but the projectile's path doesn't cross either the body's start or end position. However, this is normally not a problem for common cases like bullets or rockets, where the body is much larger and slower than the projectile.

I hope that answers your question, if not let me know!

Max

Hi,

hkpWorld::linearCast working great, i'm using a small sphere for the shape.
Thank you for the help.

Login to leave a comment.