Introduction to Unity: Particle Systems
Unity’s particle system is both robust and feature packed. In this tutorial, you’ll learn the ins-and-outs of it to create both fire and explosions. By Anthony Uccello.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Introduction to Unity: Particle Systems
25 mins
- Getting Started with Particle Systems
- Adding a Particle System
- A Closer Look at a Particle System
- More Main Module Properties
- Introducing the Emission Module
- Adding a Custom Texture
- Changing the Particle System’s Shape
- Changing Size Over Lifetime
- Building a Bomb (Effect)
- Building the Explosion
- Changing Color
- Where to Go From Here?
More Main Module Properties
Select the TorchFireParticles GameObject in the Hierarchy and scroll down to the particle system. Under the Main Module, take a look at the following properties:
Set the size to 3; this is a manageable size that lets you see the individual particles more clearly.
Keep the rotation at 0°; the particles are round so you will hardly notice the difference.
The image above is from a system with the gravity modifier set to 1, which makes the particles flow down like a waterfall. Leave the gravity in your system at 0; the particles will move upwards with the velocity you set in Start Speed.
Leave your simulation set to Local Space. The effect will only be visible once the particle system is moved.
-
Start Size: the initial size of the particles.
Set the size to 3; this is a manageable size that lets you see the individual particles more clearly.
-
Start Rotation: The initial rotation angle of the particles.
Keep the rotation at 0°; the particles are round so you will hardly notice the difference.
- Start Color: The initial color of the particles. Keep the color at the default value of pure white (255,255,255); you’ll color the fire via a texture.
-
Gravity Modifier: Scales the gravity value set in Unity’s Physics Manager window. If it’s set to 0, the gravity will be turned off.
The image above is from a system with the gravity modifier set to 1, which makes the particles flow down like a waterfall. Leave the gravity in your system at 0; the particles will move upwards with the velocity you set in Start Speed. -
Simulation Space: Moves particles in Local Space along with the particle system. While in World Space, particles move freely once emitted.
Leave your simulation set to Local Space. The effect will only be visible once the particle system is moved.
- Play On Awake: Starts emitting immediately when enabled. If this is turned off, you have to manually start the particle system via script or an animation system. Leave this setting on, as you want the fire to start when the scene starts playing.
- Max Particles: The maximum number of particles the system may have alive at once. If you try to emit more particles than this, they won’t be emitted at all. This setting is primarily for performance reasons, and the default value of 1000 particles is more than enough in this case.
Whew, that was quite a list! But as a result, you’ve learned how to add a particle system to your scene and how to customize it to your liking.
Run your scene again to see the effect of your changes:
It looks a bit more like fire every time, doesn’t it?
It needs more particles though. To do that, you need to change the emission of the system.
Introducing the Emission Module
The Emission module handles the number and timing of emitted particles in the system to create anything from a continuous flow, to a sudden burst of particles, depending on your needs.
While still in the particle system’s Inspector, click on the Emission module title:
This opens up the Emission module:
Rate over Time represents the number of particles emitted per second. Set Rate over Time to 15.
Run your scene again; your particle system looks a little more like a burning flame now.
Admittedly, it still looks like smoke. But here comes the biggest change in this tutorial so far: a custom texture!
Adding a Custom Texture
All particles have a particle material and a texture that defines how they look. There’s only so much you can do with the default texture. By changing the texture, you can create effects like magic stars, smoke and of course, fire.
Changing the particle texture is quite easy. Up to this point, the particles have been drawn on the screen using the Default-Particle material, which is a particle material with a circular gradient texture:
To change the material, select the TorchFireParticles GameObject inside the Hierarchy. Then find the the particle system component in the Inspector and open up the particle system’s Renderer module.
Open the Materials folder in the Project View, and drag the FireMaterial Material to the Material property:
Finally, run the scene to see your custom texture in use:
Can you feel the heat? The flame’s a bit too wide though; to fix that, you’ll have to change the shape of the particle system.
Changing the Particle System’s Shape
The Shape module, as the name implies, controls the shape and the behavior of particles in that shape. You can choose from several different shapes; each has their own particular settings. This lets you create particles in a box, a sphere, or even in your own custom mesh!
Expand the Shape module in the Inspector:
The shape of your particle system is set to cone, which means particles emit from the base and move outwards at an angle:
In the example above, the base is colored blue, the angle is green and the particles are red. Also notice that while you have the Shape Module expanded, you’re presented with a handy preview of the cone in the Scene view:
Changing the Angle changes the size of the cone to make it wider or narrower. Set this to 7; you’ll get a nice tight flame that widens slightly as the particles rise.
Changing the Radius changes the size of the base. The larger this value is, the more the particles will scatter as they emit. Set this value to 0.2; this ensures the flames will start inside the fuel holder of the torch.
Run your scene and see how the shape of the flame has changed:
That’s starting to look like a real flame! The finishing touch is to change the size of the particles over the course of their lifetime.