Player Hurt VFX

Daniele Quero, PhD
3 min readJul 22, 2021

Objective: Introduce an engine on fire object and set the logic for a hurting VFX

I want to introduce a new effect: when the player gets hit, fire appears on the ship. Let’s design it.

  1. There will be 2 engines on fire, at each side of the player, they are 2 identical game objects, by default inactive and activate when damage occurs
  2. We will use the reciprocal position of player and damaging object to choose which engine goes on fire. If damage comes twice from the same side, the second time the other engine will be set on fire
  3. Engine will be set on fire starting from the second player life.

The creation and animation is not anything new, remember to make the objects children to the player and to place them in proper position. This is the result I got.

Also add tags and set the ordering layer so that the will appear over the ship. Now deactivate them from inspector and let’s go coding!

First, I changed a bit the damage method. Now it asks also for a float x which is provided by the transform of who is calling the method, then calls a new method to set engines on fire. Let’s take a look, here we learn something new.

The idea is to grab the two objects and set their active state. Unfortunately, since they are deactivated by default, it is not possible to use GameObject.Find* methods. On the other hand, they are player children so we can find them through transform.Find method, suitable also for deactivated objects. We will use this method to initialize an array of gameobjects. You can learn more about arrays on my C# Learning Project with Unity.

By checking x position, we are going to choose which one is to set on fire: if is less than player x, hurt on the left, otherwise on the right.

If the engine is already on fire, the index is turned into the other one (check my Repo, to look at that method!). Once the index is chosen, the corresponding object is set to be active.

This is the result.

--

--

Daniele Quero, PhD

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams