Bullet Penetration and Projectile Physics


page 1 2 3 4

6

6_1

It is very useful for debugging and testing different materials to not just have a line trace, but to show the speed of the projectile in the line trace.

Create a GetTraceColor function (pure) which accepts a velocity and outputs a color. You can simply use one lerp to fade from a color at top speed to white at 0 speed, or use a more complicated setup as pictured.

7

Add a Vector variable LastPosition to the FirstPersonProjectile blueprint. In the ConstructionScript initialize it to the actor location.

Optionally add a TraceDuration variable to universally control the duration of the bullet's trail.

In Event Tick, use the draw debug line function to draw from the last position to the current position, then update the last position variable.

8

Add a similar draw debug line function immediately after the OnProjectileBounce Event, from the last position to the hit location (with color dependent on the impact velocity). Finally, if the projectile did bounce/did not penetrate, draw a line from the hit location to the current location.

9

If desired, change the InitialSpeed property of the ProjectileMovementComponent to something more realistic (eg 30,000cm/s).

Also change the life span of the actor to be larger than 3 seconds.

10

10_1

Create a GetNewSpeed function (pure) with inputs for the hit, exit location, and impact velocity. It should return a float.

Energy lost is calculated by multiplying the distance penetrated * a material dependant constant. The bullet's energy can calculated with E=0.5mv^2. The new speed is calculated with a rearrangment of this: v=sqrt(E/0.5m)

11

11_1

Now that we have a new speed function, connect it up in the event graph.

Check that the new speed is > 0. If so, set the new projectile's speed to this. If not, destroy the original projectile.

12

You should now be able to test that the projectile loses velocity proportional to the distance it penetrates.

page 1 2 3 4