Explosions

It was already mentioned above how the OnCollisionEnter2D and OnLaserCollision events instantiate explosions; either – in the case of a bullet – its own explosion and/or the receiving object’s explosion. This section goes over how that is all handled.


When a bullet’s shot script detects a collision, it’s OnCollisionEnter2D method is raised via the ShotBullet class as well as the base class ShotBase. The ShotBase method simply determines if a bullet is destroyed or repooled, whereas the ShotBullet method determines if an explosion is requested.

The type of explosion requested (if any) is set by [A] the shot script’s Explosion field. Here you enter the explosion’s name (more on this in a moment). You can also set whether or not the explosion’s rotation follows the bullet’s trajectory with [B] Explosion Rotation and whether or not it becomes parented to the object it is colliding with via [C] Parent Explosion.

Also, because you may not want all collisions to result in an explosion, you can filter and accept only the collision layers that result in an explosion via [D] Collision List.


Meanwhile, a ShotCollision/ShotCollisionDamage script operates in much the same way and can create its own collision explosions by filtering which kind of shot results in an explosion through its [E] Collision List and even set different types of explosions depending on if the incoming shot was a Laser or a Bullet via [F] Laser Explosion and Bullet Explosion.

Enabling [G] Parent Explosion is best used in cases where the object receiving the collision is moving (such as an enemy, player, etc).


The default Explosion prefabs themselves are stored in Assets > ND_VariaBULLET > Prefabs > Explosions


Explosion requests are called via the collision event methods mentioned above and sent to the GlobalShotManager, and so you must load the explosion prefabs into the GlobalShotManager in the resources folder ahead of time to fulfill those requests.


Explosion prefabs takes on the familiar structure of [A] holding animation Frames and Frame Skip. It also carries it’s own [B] Sound FX clip which the GlobalShotManager plays and you can prevent the GlobalShotManager from repooling the explosions via [C] Prevent RePool.