Player damage: Visual effects (VFX)

Hal Brooks
2 min readJun 12, 2021

--

Objective: Add animated visual effect for damage to the player using Unity

Player damage VFX.

The engine damage animation uses two game objects, right & left engine, which are children of the player. Child objects remain attached to the player and move with the player.

Create the Right_Engine by dragging the initial sprite art from GameDevHQ FileBase into the heirarchy and rename it. In the Sprite Renderer, the sorting layer is set to foreground with the order in the layer set to 1 so that it is on top of the player, foreground layer 0. Create an animation named Engine_Damage_anim. Drag the sprite sequence into the animation window. The controller will automatically renamed to the that of the game object, so rename it Engine_Damage and reassign in the inspector. The Left_Engine is a duplicate of the right engine with a negative X position. The box next to Right_Engine & Left_Engine should be unchecked so that they are not displayed at the start of the game.

The player damage functions are within the Player script so create an private GameObject[] _engines array variable and assign the left & right engines in the inspector, as shown below.

A simple if statement checks for the player lives after taking damage. If _lives are two then _engines(Random.Range(0,2)).SetActive(true) turns on a randomly selected engine to start burning. If _lives is one then both engines are set to active. The player is destroyed if _lives are ≤ 0.

Excerpt from Player script

The player now appears to start burning upon taking damage.

--

--