Math behind bullet penetration

I’m trying to implement bullet penetration in my game, unfortunately math is not my strong suit.

Here is an image behind what I’m trying to do.

So currently I have a line trace from StartPosition to (StartPositionVelocityDeltaTime). This line trace will result in a hit if the bullet collides with something. This gives me ImpactPoint. With the line trace, I have SurfaceNormal, ImpactPoint, and StartPosition.

What my plan was, is to take the ImpactPoint and move it some arbitrary distance in the same direction, then do a line trace from that new location to the original ImpactPoint. This should give me the ExitPoint, where I can do stuff like check if the object is too thick to be penetrated by the bullet.

My question is: how do I calculate what the TestPoint is? What my guess is that I need to get the normalized vector from ImpactPoint back to StartPosition, multiply that by my arbitrary distance, then add it to ImpactPoint to get my TestPoint. Unfortunately I have no idea how I would calculate that vector.

Solution is way too simple :stuck_out_tongue:



		FVector HitAngle = ActorLocation - HitResult.ImpactPoint;	
		HitAngle.Normalize();


EDIT: seems to be broken when shooting down the Y axis

I remember doing this back in UDK. The solution is still simple

Use GetWorld()->LineTraceMulti

This will return all the “entry” points of your trace. Rubbish ascii diagrams follow…



Start ->  |1| -> |2| -> End


The trace will have the hit points of both 1 and 2

For each hit result, trace backwards (invert your trace direction) doing a single line trace. Remember to trace from your end point too so that the exit point of the last actor is included. Also don’t trace backwards from the first hit, that will just hit the actor that fired the trace :wink:



 |1| <- |2| <- End


This gives you the exit points of each of the previous items.

At each hit result add a particle effect.

For extra credit, you can give the bullet a strength, and for each actor it travels through, reduce the strength of the bullet based on the impact material and how far it travelled (VSize of entry + exit points). Eg certain weapons wont go through metal, others will a little, and yet others go through metal like paper.

If you don’t want the extra credit, do a LineTraceMulti from End to Start (ignoring the firing actor), that will give you all the exit points in one go.

Anyway, I ramble… Hope that helps :slight_smile:

Hate to bump this thread, but how would I do this for BSP and Static meshes?

As long as they respond to trace queries it works exactly the same. I’m not using any BSP so don’t know what you have to setup there but for Static Meshes just make sure that they block trace channel which you use to run traces on.