Damage VFX using Animated Sprites in Unity

Dennisse Pagán Dávila
CodeX
Published in
3 min readMay 7, 2021

--

In the Lives Counter article, I talked about how losing lives in a video game has to be made obvious to the player as a principle of good game design. While there are multiple ways to achieve this, direct visual feedback thrives among the best. With the increasingly popular minimalistic UIs, more and more games rely less on that aspect to represent player data. The Uncharted franchise was among the trendsetters with its HUD only displaying ammo, and the player damage being represented visually by turning the corners of the screen red.

Uncharted 2: Among Thieves

In this article, we’ll take a look at how to add VFXs when the player gets damaged.

Setting up the VFX for player damage

  1. Make the desired sprite into a child of your player object, then scale it as needed. This is done because the damage VFX needs to move along with the player, and parenting essentially means that all of the child’s transform changes are performed in perspective to that GameObject rather than the game world.

2. If your damage sprite appears to be under the player, add a new layer so that it always displays above it. In my case, I have already added one. Layers that are at the bottom will appear above the ones at the top.

3. Animate the damaged Sprite. In my example, I am using a sequence of sprite images for the sprite animation.

4. Disable the Damage VFX in the Inspector. This way, we can activate through code at the right time. I copied one of the damage VFXs in order to have one per engine.

Displaying when the player is damaged

The following example demonstrates part of my Player code. The code for the damage VFX should be placed in the script where the player’s lives get subtracted.

  1. Create GameObject variables to reference the damage VFX in the Inspector.

Note: These are two separate variables but since they share the same type and over structure, they can be declared as such.

2. Place the damage VFX in the respective spaces created by step 1. This will allow us to manipulate it through code.

3. Activate the damage VFX went the player loses X amount of lives/ when lives equal a certain number of your choosing.

The Result:

In the next article, we’ll take a look at How to use Post Processing in Unity!

--

--

Dennisse Pagán Dávila
CodeX
Writer for

Software Engineer that specialize in Game Development. Currently looking for new opportunities. Portfolio: dennissepagan.com