Enemy Explosions when Destroyed — Part 1

Frank Warman
3 min readMay 1, 2021

--

We’ve got our Main Menu working and it feels like a decent game so far. But we still some more of that pizzazz to keep the Player coming back.

What better way than with some Michael Bay-esque explosion VFXs that just feel so satisfying to be the one to cause them!

In these next couple articles we’ll be creating and utilizing Enemy Explosions!

Enemy goes boom!

Creating the Animation

We’ve created an Animation before and this is no different. Click on your Enemy Prefab, open up the Animation window and create a new Animation Clip:

Create new Animation Clip

Then add your Enemy Explosion Sprites to the Animation Timeline:

Remember you can select the top Sprite, then Shift-Click the bottom Sprite to get everything in between!

With our Enemy Explosion VFX it looks something like this:

EXPLOSION!

We have to remember to turn off Loop Time for this animation, since we don’t want the explosion to continue more than once.

Empty Animation States

If you’ve tested your Game after creating this explosion, you’ve probably ran into a slight problem… Something along the lines of this:

Instant death

Our Enemies immediately explode upon being Spawned! That’s not good.

This is because when you first create an Animation for a new Animator Controller, that animation is set to the default state. So as soon as the Enemy is Instantiated, it goes into this default state, destroying itself!

We don’t want that, so we’ll create and Empty State in the Animation Controller and set that as the default. Then we can use some coding to trigger our Explosion when needed!

In the Animator window, an Orange Animation is the default state.

In the Animator window, we right-click and click Create State, and select Empty. Then right-click the new state and make it the default state.

We’ll also create a Transition to our Enemy Explosion VFX that we’ll utilize with code.

Creating an Empty State and changing to default.

With our Transition created, we’ll need to create a Parameter to trigger the transition. In the top-left of the Animator window, click on Parameters, then the Plus icon and select Trigger:

New Parameters

We’ll call this Trigger OnEnemyDeath. Now we can select our Transition we made and under Conditions in the Inspector window we’ll select OnEnemyDeath.

Linking a Parameter to a Transition

And make sure to turn off Exit Time as well in the transition. This makes sure that the Animator will jump from the Empty state to the Enemy Explosion state immediately.

We’ll continue this section in the next article, where we’ll look at triggering the animation through code, fixing some problems that arise, and jump ahead in time where I fix a bug from a few sections ahead.

--

--

Frank Warman
Frank Warman

Written by Frank Warman

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles