Get exit position of bullet

Topics: Developer Forum
May 17, 2011 at 5:25 PM

Is there a way to get the exit position of a projectile, given the entry point and trajectory? Basically, I would like a bullet to hit an object of width "X" and return the coordinates of where the bullet will exit the body (if it continues on it's current trajectory). I have a feeling I should be looking at the RayCast method, but that seems to require an end value, but I don't know the end value of the trajectory. Is there a way to do this? Thanks for any help.

May 28, 2011 at 5:08 AM

From what I know, Raycast would be the best way, and to get the exit position, you would "backtrack" your ray (start beyond the exit point, and end it on the entry point). To find out the start position from this, you can get the direction of the bullet, and the aabb of the object that was hit, then calculate from that a point (x,y) that is outside of the aabb in the direction of the bullet. I don't know the math of this off the top of my head, but its fairly simple (also make sure your raycast hits the correct object too).