Ballistic Surfaces - Penetration
Last updated
Last updated
We have modified our cube's position in previous tutorials, so let's put it back to 0,2,10 before continuing here. Also, make sure our main camera's field of view is set back to 60.
When you want any of the objects in your scene to be penetrable by bullets, you need to attach BallisticSurface.cs script onto your objects. Let's add this component to our cube object in the scene.
You can use the Preset drop-down to select various different surface presets. For the sake of the tutorial, we will use the Custom preset, and adjust the variables ourselves. For this tutorial, we are only interested in penetration, so go ahead an uncheck the Ricochet Enabled checkmark. When a bullet starts penetrating a surface, it will lose it's kinetic energy depending on the Energy Consumption slider. Here, a value of 1.0 means losing 100% of the bullet's kinetic energy, while 0.0 means losing none. Min Energy denotes the minimum kinetic energy a bullet should have in order to be able to start penetrating this object. Deflection Angles two-ended slider allows us to define an angle range, which will be used to select a random exit angle for the bullet. Let's leave the settings like this for now, except that we have unchecked Ricochet Enabled mark, so it will look like this:
If you play the game and hit space now, you will see that the bullet will penetrate the object.
More the bullet ray stays inside the object, more kinetic energy it will lose, depending on the Energy Consumption. So, object's thickness will affect how the bullet penetration continues. Go ahead and change our cube's scale to 6 in Z axis, so it's scale will be 5,6,6. Then play the game, hit space bar. You will see that the bullet still penetrates, but loses so much of it's kinetic energy that it basically falls into the ground right after exiting the object.
If you were to further increase Z axis scale, say to 8, then the bullet ray would not get out of the object. Also, the thickness doesn't have anything to with the actual Z scale of the object. So, say you set the Z scale to 8, preventing the bullet from penetrating. But if you moved the cube to such a position that the bullet should enter from not-so-thick part of the cube, it would still penetrate.
Of course you can tweak this behavior completely to your liking by changing the Energy Consumption value. Finally, let's change the Deflection Angle value, to be somewhere between 50 and 60.
Now if we were to fire multiple shots continuously, we would see that they would be deflecting from the linear path randomly according to the deflection angles.
Now let's take a look at the Ricochet settings to see how the bullet rays would ricochet off the surface.