Is your game lacking that little extra? Maybe defeating enemies isn’t all too satisfying and can get very repetitive? Well I have a solution for you – Particles!
Particles can improve gameplay massively and add that extra element to your game that people might not always realize. They are very small sprites or models that can create all kinds of effects from explosions, fire, water and even lightning!
Luckily, Unity has a built in Particle System component and I will explain how to use it below. By slightly altering the properties of a particle system, the possibilities are almost endless!
Think of having a rain cloud in your game. You don’t want to instantiate every single rain drop over and over again as this will take a while to implement and also use up a huge amount of memory, in turn slowing down your game. Instead, using a particle system of blue drops that have a gravity element to make them fall down is much more efficient, and it can also improve the appearance too.
They are also very useful to make your game more engaging. When you shoot an enemy, rather than that enemy just disappearing into thin air, how about it exploding into a bunch of pieces? Techniques like this are known as “Game Feel” or “Game Juice” and might go slightly unnoticed by the player, but without them a game can be very monotonous and less interesting. Look at these gifs: one has no particles, and the other instantiates particles when an enemy is defeated.
Click the button below to download the zip file for this tutorial. This file contains a Unity project with all the assets we will use in this tutorial, along with some ideas of particle systems that you can use and edit to your requirements.
To start, create a new Particle System by right clicking in the hierarchy Effects → Particle System.
The particle system will start its life as a constant stream of shapes smoothly floating up. It’s now our job to mold this into a unique design to suit our needs so we will learn how to manipulate the main elements of the Particle System.
The Duration determines how long the particles will emit for, so for short bursts, a smaller duration is needed.
Looping is very useful for continuous animations, like the rain example above. It means only one particle system is needed and will continuously run and reset itself in game.
If you have looping enabled, it could be a good idea to check the Prewarm box as this will make sure the Particle System will start after the first loop. Without this box checked, the loop will start from nothing when the game is played and so the cloud will only just start raining.
On the left is a system without Prewarm checked, and on the right is one with it checked.
A lot of the time, a particle system works best when it has an element of randomness to it. Say you set a particle system to instantiate whenever you pick up a coin for example. It can feel more rewarding and interesting for the player to see a slightly different pattern each time.
We can easily achieve this by setting some attributes to be random between values (you can choose this option by clicking on the triangle next to the property you want to randomize).
Setting the Start Lifetime to be random between two constants will make some particles last longer in the world than others so the effect doesn’t just end all at once when it’s finished.
Having particles shoot off at different speeds will make the system much less static in appearance so setting the Start Speed to be random can also be useful.
In an explosion, not all the pieces of debris are the same size, so making the Start Size random will give some particles that are big, and some that are small to add a sense of realism.
It’s the same idea with the Start Color. Setting it to be random between two colors will add that extra hint of spice that will keep it engaging for the player.
This Particle System has most attributes set as random and is always unique in some form:
The Emission and Shape attributes are what decide how the particle system shoots out each individual particle.
Setting a higher Rate over Time will make more particles shoot out over the duration of the effect.
Using Bursts can create a great effect as it will shoot out the specified number (randomness will be useful here too) of particles at the same time, in specified time intervals. Setting the Rate over Time to be 0 and making only one burst appear at time 0 will make one explosion of particles occur, which is useful for an item pickup as you don’t want a continuous stream.
These explosions are a good example of how bursts can be used for item pickups:
You could also add a dust effect for when your character is running on the ground by adding a Particle System to their feet and setting the Rate over Distance attribute to be a positive integer. This will make the system emit a number of particles only when it is moving.
Changing the Shape attribute will determine the direction and how far away from the center a particle can form. So, if you want your particles to only emit only in a straight line for example, use the edge shape.
The Velocity over Lifetime attribute is one of my favorites to play with because you can make the particles move in any shape you want, from simple sin waves to tornado effects.
The Linear attribute just makes the particles move in a straight line towards the direction of whichever axis has a value which isn’t 0.
The Orbital attribute will make the particles rotate around the axis, and using these two together can give you all kinds of patterns.
Setting some of these values to be random can be useful. For example, setting the Orbital Y value to be in-between –2 and 2 will make some particles rotate clockwise around the Y axis and the rest rotate anticlockwise. For a tornado effect, you can simply make the particles rotate around the y axis, whist simultaneously moving up it.
Below are some simple patterns that can be made by altering the Velocity over Lifetime.
At the moment, when our particles reach the end of their lifetime, they are just disappearing immediately which doesn’t feel crisp and seamless.
To help combat this, we can use the Size over Lifetime attribute and set the curve as below. This will make each particle get smaller and smaller over its lifetime and eventually fizzle out of existence rather than harshly disappearing.
Adding collisions to your particles can be used if you want them to interact with the player or the floor.
Say you have a waterfall made from particles, adding a collision element can make the water move around the player when they run through it, adding an extra dimension to the world. It is best to use Planes as the Type but this is not always possible if you want the particles to interact with world objects. Note that it could negatively affect performance if you have a lot of particles that are continuously looking for and detecting collisions so keep this in mind.
On the left is a system with Collision enabled, and on the right is one without.
The Sub Emitters attribute is amazing for a firework effect.
You can set the Particle System to be a single particle (the rocket) that shoots up in the air. Then add another exploding Particle System and set it as a child of the original system. Setting the Sub Emitter of the original system to Death and adding the child as the Particle System element will make the explosion only appear once the original rocket has gone, giving the effect of the rocket exploding into little pieces.
A particle trail works exactly like a normal trail renderer on a game object, but you can choose the percentage of particles that will have a trail. You will need to set the trail material under renderer to a suitable material you have made.
For this, you can use a soft brush tool in any photo editing software and make a rectangle sprite like below.
Then right click in Assets and choose Create → Material. Set the shader to Particles → Standard Unlit and set the Rendering Mode to Additive and Color Mode to Multiply.
Finally use the new rectangle sprite as the Albedo and set this as the Trail Material back in the Particle System.
Similarly, you can do this with a sprite instead of a rectangle and set it as the Material under Renderer to make each particle a sprite rather than the default circle.
Now you have the knowledge on how to use and manipulate Particle Systems to your advantage to add new dimensions to your games. Maybe go through your past projects and add these when you pick up items or defeat enemies and see how much it improves the feel of the game.
There are many more effects that you can create with particles which we haven’t shown in this tutorial such as electricity, flames and smoke. Go ahead and play with each element and see what cool particle effects you can create for your game!