Implementing Confetti Coming out of an object In Unity

Implementing-Confetti-Coming-out-of-an-object-In-Unity

A Particle system is a component of Unity which is used to add some extra effects in your game like fire, flowing water, smoke etc. which is not possible through the normal game object having meshes and textures. A particle system generally emits particles in random positions within a predefined space.

Particles are small, simple images or meshes that are displayed and moved in great numbers by a particle system.

In this tutorial, we will implement a particle system which will look like a confetti.

Prerequisites:

1

Unity 5 or higher.

2

In this tutorial, we will use Unity 5.6.3.

This tutorial covers following topics:

1

How to add a new Particle System?

2

Manipulating Particle System

How to add a new Particle System?

To add a new particle system click on GameObject in Menu and then select Particle System. As it is a component you can also add it to an empty gameobject from Component ->Effects -> Particle System. Now select particle system from scene hierarchy. You can see a Particle Effect dialogue in the scene view which allows you to Simulate and Stop particle system. Set the camera’s clear flag to Solid color and set color black. Also, set the projection to Orthographic so we can see the effect of the particle clearly. Also set camera position to (0,1,0).

Particle-Effect-Dialogue

  [Particle Effect Dialogue]

Manipulating Particle System

To create confetti-like particle system we need to manipulate the default particle system. Create a new particle system and name it “Confetti”. Set its position to (0,-1.87,5)and rotation to (-90,0,0). The default particle system has several sub-sections as shown in the inspector.

ParticleSystem-Inspector

[Particle System Inspector]

First of all, create a material and name it ConfettiMat and set its shader to Particles ->Anim Alpha Blended. Set it in the Renderer section of particles system in the inspector.This applies a material to a particles system and renders it in camera.

Now set the following values :

1. Duration : It is The length of time in seconds for the particle to run. Set this value to 0.1.

2. Looping : if true, the emission cycle will repeat after the duration.Set it true.

3. Start Delay : The delay in seconds before the particle system start emitting. Set this value to 0.

4. Start Lifetime : The initial lifetime in seconds for the particles. The particle is destroyed after this elapsed time.Set this value to 8.

5. Start Speed : The initial speed of the particles. The greater the speed of the particles, the more spread out they will be. Set this value to 20.

6. Start Size : the initial size of the particles.Set this value to 0.25.

7. Start Rotation : The initial rotation angle of the particles.Set this value to 0.

8. Start Color : The initial color of the particles. Set the type of value to the gradient. Click on the color part, it will open a Gradient Editor window. Set the color values as shown in the image. You can also set it as you want.

Gradient Editor

[Gradient Editor]

9. 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. Set this value to 3.

10. 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.

11. Max Particles : The maximum amount of particles the particle system is allowed to have alive at any time. Set this value to 300.

12. Emission : The Emission module is one of the most important modules in Unity particle systems; it handles the number and timing of emitted particles in the system to create a continuous flow or a sudden burst of particles depending on your needs.

13. Rate over time : It is the number of particles emitted per second (Time), or alternatively, per unit (Distance) 300

14. Shape : The Shape module, as the name implies, controls the shape and the behavior of particles in that shape. Set its value as following :

Confetti Particle Shape

[Confetti Particle Shape]

15. Force over Lifetime : Controls the force of each particle during its lifetime. Set its value as shown in the picture:

Confetti Particle Force over Lifetime

[Confetti Particle Force over Lifetime]

16. Rotation over lifetime : Controls the angular velocity of each particle during its lifetime. Set the value as shown below:

Confetti Particle Rotation over Lifetime

[Confetti Particle Rotation over Lifetime]

17. Collision : Allows you to specify multiple collision planes that the particles can collide with.Create an empty gameobject and name it Surface. Set its position to (0,-4.1,5) and add BoxCollider component to it. This will allow the particles to collide with surface and create real-time confetti-like physics effect. Set the value as shown below:

Collision

[Collision]

You can create as many planes as you want for particle collision.You can also rotate that plane using rotation tools in

particle system -> collision -> scale plane Rotate plane

Click on the simulate button, and you can see colorful particles like confetti. Now create a Cylinder gameobject and set its position to (0,-2.81,4) and scale to (1,1.2,1).

Now hit the play button, and you can see confetti particle coming out from the cylinder.

Confetti
Ketan Jogadiya
Ketan is a Unity3D game developer at Nimblechapps, a Unity 2D/3D game development company based in India. He is passionate about new technologies in mobile games. He is game developer by day and writer by night.