2D Mobile Game: Enemy Death Animation

Ryan McCoach
3 min readApr 26, 2022

--

Intro

In this article, we will cover how to add a death animation to a sprite and in this case the enemy sprites.

Animator Setup

After slicing all of the different enemy sprite sheets and creating the animations, we want to make sure that each of the Death animations have Loop Time false. This prevents the Death animation from playing over and over again, but instead will only play it once.

In all of the Animators that now have the Death animation, we want to be able to transition to the Death animation at any point or in Any State. This will require a trigger parameter that will be the condition for the Animator to transition to the Death animation and we will call this trigger parameter “Death”.

Coding the Animation

Each of the enemies have a Damage method that checks for when the health is below 1. This is where we set the death trigger through the Animator handle anim.

The Death animation is being triggered, but we notice the enemies movement logic is still active.

Looking at the Enemy Class script, the enemies will not move when they are in idle AND they are not in combat.

We will need to create a bool (isDead) to help use control the movement depending on when the enemy is dead. This is set to false by default because the enemy is not dead when the game starts.

In each of the enemies’ Damage method, when the health is less than 1 and where we are triggering the death animation, we will also want to set isDead true.

Back in the Enemy Class script, we can have the Movement method only be called when isDead is not true or is false.

Cheers!

--

--

No responses yet