VFX in Unity — Visualizing Player Damage
Goal: Visualize damage in Unity using animated sprites
VFX again, in video games, are what make your visuals stand out. But they also serve as a communication between the code and player. For example: how does a player know, in an efficient way, that they’re damaged?
In our Space-Shooter game, we visualize damage by either engines being destroyed, leaving a trail of smoke and fire.
We already have frame-by-frame sprites to create such animation.
First, we drag one of these frames as a child object under the Player, name it, then position it.
Now to animate this, we open our Animation window, create a new animation, and drag and drop those sprite frames.
This is what we get:
We then duplicate this object onto the other side. It will carry over the same animation.
Now we have to implement the logic for this.
First, these damage visualization objects will be off when we start, so disable them hierarchy window.
In our Player script then, we have to get references to them, and assign them through the inspector.
Then, where we implement logic to damage the player we then also check the amount of lives we have.
If we have 2, then we’ll enable one damage visualizer, because that means we just lost one life. The same goes if we have one life.
And this is our VFX in the works:
And that’s all! This is rather a short and simple article, as it builds off the previous VFX one discussing about explosions.
Hope this helps, and have a great game-dev day!