Creating Enemy Explosions

Giving more video game feeling with some animations

Rusben Guzman
3 min readJun 21, 2021

Objective: Make an enemy explosion when the enemy is destroyed.

Currently when we destroy an enemy it just disappears from the scene. Let’s add some animation to this.

First we have to open the enemy prefab, go to the animation windows, create an animation and add the respective sprites for the animation. In this case we have to uncheck the loop time in the controller because the animation has to run just once.

Then Open the animation controller, create an empty state and set it as default. We do this to avoid running the explosion animation when the game starts. After that we’re gonna create a parameter of type trigger called OnEnemyDeath to trigger the animation through script.

In the enemy script we have to declare a variable to get the animator reference. Then create an Explode function where we are gonna use the method SetTrigger from the animator to trigger the explosion animation, set the speed to 0, disable the collider and destroy the object.

That Explode function has to be called in each case where the enemy is destroyed.

Nice! We are good to go. When we run the game we can notice the enemy explode when it is destroyed by a laser or colliding with the player.

--

--

Rusben Guzman
Rusben Guzman

Written by Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.

No responses yet