This week we made an explosion force in our WIP shmup. This turned out to be much more complicated than it would appear. To start with we created an explosion object that consisted of a sphere collider and a rigid body. Then it needed a script. However, our script turned out differently to that of other methods floating about the internet, such as the unity Space Shooter Tutorial. Our explosion script gave a moment before dealing damage to the enemies within its range and also has the ability to be altered and elaborated at any moment. Our explosion also does no damage to the player. Also, rather than immediately destroying the enemies inside the explosion space, our explosion script causes the enemies to take damage. Alternatively, the unity tutorial instructs you to make the explosion destroy all colliding objects and destroy the player if they are within the range.
I personally would have never thought of doing the explosion in this way if I were to implement it myself. I would never have thought of the explosion delay if I were doing it on my own. If I was to be doing the explosion damage script on my own I would never have thought to use the spherical collider, but instead I would have considered all the objects existing at that moment and then would have considered their distance from the epicentre of the explosion when dealing damage and destroying objects. I also would have just straight up dealt the damage when the button was pressed rather than giving a moment for all the objects to be collected and then for the explosion effect to appear as though it’s doing something. Another great thing about the explosion script we created is its spectacular flexibility. It enables us to drag the prefab explosion into any situation and alter the variables so that it can deal all range of explosion damage in all different areas of effect. One issue I’ve found with the current explosion damage script is scaling the damage so that not all the enemies die when they are hit, but this could be solved with some adjustment of the damage value. Overall the code works well and any real drawbacks are of my own additions not the standard script. The addition of explosion damage was a very important step in creating this shmup because it allows us to apply damage to lots of things that are scaled by distance rather than simple collision.