Showing Damage Effects with Animated Sprites

Blake Zoeckler
2 min readMay 15, 2021

So far we have a player that can take damage, but the ship looks exactly the same after taking a hit. It’s a good idea to make the damage effect a bit more realistic by placing a fire trail sprite on the player. It’s easy to set them up attached to the player and animate them like so:

Also new here is the “thruster” effect added to the player, and a spinning asteroid that begins the game when it is destroyed.

However these fire trails will always be present even when the player is undamaged. We want this damage effect to only appear when the player takes a hit. We can deactivate the damage sprites in the inspector:

Now let’s open the Player script and modify what happens when the player takes damage.

We need a new variable that stores these fire trail game objects. Then, in the method where the player takes damage, we can add a new switch statement that checks the number of player lives and activates the fire trails as necessary.

Make sure that these game objects are assigned in the Inspector. We would get an error in game if we forgot this step!

It’s good to make this an array in the script because it will be much easier to modify this later. Say we change our mind and want the player to have more than 3 lives, and more damage effects. Because they are stored as an array, we can just increase the size of the array and drag in any new damage sprites that we have.

Looks good! Now whoever plays the game will be able to tell at a glance that their ship needs repairs at the next docking station.

--

--

Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.