“PK creative Spring Festival, I am participating in the” Spring Festival Creative submission contest “, please see: Spring Festival Creative Submission Contest”


๐Ÿ“ข preface

  • The year 2021 will soon be over, and the Spring Festival will soon come. I wish you all a happy and prosperous Year of the Tiger in advance.
  • So today, let’s make a special fireworks effect to add some joy to our upcoming New Year!
  • Let’s learn how to make it with Y.

๐ŸŽฌ Create a simple fireworks special effect

Here we use Unity’s special effects to create this firework. This article is a good opportunity to learn about Unity’s special effects system.

Effects are created as follows:

The first thing we need to think about is the components of a firework: first we have a body, then we have a wake as the firework flies, and then we have the spherical rain of light as the firework explodes, and then we have the special effects as the firework flies.

It’s basically made up of four parts

  • Firework: Main body of a Firework
  • Trail: Wake effect
  • Explore: Explosive ball light rain
  • Fire Samll: Flying fireworks
  • Explore2: Explosion four astigmatism rain

Let’s learn one by one to make special effects in Unity to practice it!


๐ŸŽฅ Particle effect making process

โค๏ธtrail: Wake effects

Let’s start by creating a wake effect before a firework explodes.

The desired effect is that the particles grow from small to large, the color changes and the wake diffuses. Let’s set the particle parameters to achieve this effect.

  • Right click โ†’ Effects โ†’ Particle System To create a new Particle System, and we’ll call it Trail.

  • Set particle size dynamics: Open the Trail particle System panel and check the size over Lifetime option. Set the curve of particle size change in motion at the bottom of the panel as follows:

This figure means to control the size change of the particle when it is produced. The effect in the figure is as follows:Grow slowly, keep the size for a period of time, grow slowly, grow instantly, grow instantly

  • Set particle color changes: Open the Trail particle System panel and check the Color over Lifetime option. And set the color as follows:

The color change here is a color change from the particle to disappear, you can set the effect freely!

  • Set particle motion: Open trail’s particle Systems panel and check the Velocity over Lifetime option. Select Random between two curves as the velocity change mode of particle motion. Then set the velocity curve along the x and Z axes as follows, so that the particle appears to have a tail diffusion effect.

  • To set the direction of particle emission: Open the particle system panel of trail, check the Shape option, and select Shape as Sphere.
  • Emission and particle system main template: here we modify the particle speed and size and the Emission number

๐ŸงกExplore: Explosion ball light rain

Fireworks will appear when the explosion of a similar spherical explosion effect, here to make a ~

Like the tail effect, we also need the firework to spread out from the center, and then the color of the particles will change, and the size of the particles will generally change from small to big to small.

Let’s adjust the parameters to make one:

  • Create a new Particle System and name it Explore.

  • Set particle size dynamics: Open explore’s particle systems panel and check the size over Lifetime option. The curve of particle size change in motion is set below the panel as follows:

  • Set particle color dynamics: Open explore’s particle systems panel and check the Color over Lifetime option. You can set the color you like:

  • To set the direction of particles: Open the Explore particle system panel and check the Shape option. And select Shape as sphere. The particles are then formed in a spherical shape and spread up, down, left and right.

  • Set Emission and particle system master templates

๐Ÿ’›Fire Samll: Fireworks in flight

Then we’ll do a flying firework effect

  • Create Small Fire: Right-click Effects โ†’ Particle System to create a new Particle System, and let’s call it Fire Small.

  • Set the particle’s Render image to Flame 01: Open Fire Small’s particle system panel, turn on the Render option, and change material to Flame 01.

Flame 01 is a set of Flame images.

  • Set up the animation: Open Fire Small’s Particle System panel, open the Texture Sheet Animation option and set it as follows:

The Mode Mode is set to Grid by default. X =7 and y=7 in the Mode Tiles indicate that we have shard the Flame 01 image into a 7 ร— 7 grid, with each grid representing a frame of the animation. Our animation will play from frame 1 to the last frame, frame 49. Leave other attributes as default; In this way, the particle we produce will be a self-changing particle.

  • To set the direction of the particle: Open the Fire Small particle System panel and check the Shape option. And select Shape as cone, which emits particles from the bottom or top of the cone. The Settings are as follows:

  • Angle: the opening amplitude of the upper and lower surface of the cone, that is, the surface emitting particles, relative to the opening amplitude of the lower bottom surface, 0 means that the opening amplitude is the same as that of the lower bottom surface. Thus, cones in Fire Small are cylindrical;
  • Radius: The Radius of the lower base of a cone;

Use the default values for other values. However, since the original direction of the top and bottom surfaces of the cone does not directly point down, we need to rotate the particle system. The Fire Small transform is as follows:

  • Set particle shake: You can see that our fireworks are constantly shaking as they move. This is to simulate the shaking effect of the flame caused by air flow in the flying process of fireworks, so we can directly check the “Noise” option. You can control the jitter frequency by controlling the intensity.

  • Set particle color dynamics: Open the Fire Small particle System panel and check the Color over Lifetime option. And set the color as follows:

๐Ÿ’šExplore2: Explosion four astigmatism rain

Our fireworks should not only have a spherical rain of light after exploding, but also have a scattering effect.

  • Create Explore2: Hierarchy panel Right click Effects โ†’ Particle System to create a new Particle System, and let’s call it Explore2.

  • Set the Render image of the particle to Twinkle: Open Explore2’s Particle System panel, open the Render option, and change the Material to Twinkle.

  • To set particle emission direction: Open Explore2’s Particle Systems panel and check the Shape option. And select Shape as sphere, that is, to launch particles in spherical shape. The other need not change;

  • To set dynamic particle Rotation: Open Explore2’s particle system panel and check the Rotation over Lifetime option. You don’t need to change any values.

  • Set particle motion: Open Explore2’s Particle Systems panel and check the Velocity over Lifetime option. The Settings are as follows:

  • Add gravity to particles in motion: Open Explore2’s Particle Systems panel and check the Force over Lifetime option. And the z-axis force is set as -20, so that the particles are subjected to gravity and fall to the ground after the explosion, simulating the natural gravity.

  • Set trail: Open the Particle system panel for Explore2 and check the Sub Emitters option. Add a finished trail child to Explore2 to become a child of Explore2. Then set TRAIL to Explore2 seed subsystem as follows:

  • Set Emission and particle system master templates


๐Ÿ’™Firework: Fireworks main body

Several parts of the fireworks are finished, the next to add a main body, the previous several particle effects to add together!

  • Create Firework: Right-click Effects โ†’ Particle System to create a new Particle System, and let’s call it Firework.
  • Put the particle effects together.

  • To set the direction of particles: Open the Particle system panel in Firework and check Shape. And select Shape as box, that is, to emit particles with a square. Since box’s default emission direction is in the positive z-axis direction, rotate Firework as shown below:

  • Set particles not to Render: Since Firework’s particles do not need to be rendered, we set Render mode to None in the Render option;

  • Setting the daughter subsystem: Similar to Explore2, we check the Sub Emitters option and insert all of Firework’s daughter subsystems into it as follows:

Among themDeathParameters are events that are triggered at the end of the particle cycle.

  • Set Emission and particle system master templates


๐Ÿ”” Create a fireworks scene

A simple fireworks special effect has been created, then use a script to control the mouse click to start the fireworks.

The script code is as follows:

public class FireFirework : MonoBehaviour
{
    public ParticleSystem _firework;
    public ParticleSystem.Particle[] m_Particles;

    void Start()
    {
        _firework.Stop();

        if (m_Particles == null)
        {
            m_Particles = newParticleSystem.Particle[_firework.main.maxParticles]; }} [System.Obsolete]
    void Update()
    {       
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);// Emits rays from the camera to the click coordinates
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Debug.Log("Mouse point position:"+hit.point);
                _firework.Emit(1);
                // Get the running particles belonging to Firework [id] in the scene;
                int count = _firework.GetParticles(m_Particles);
                // Calculate the flight time of fireworks according to mouse click position;
                float life_time = (hit.point.y - gameObject.transform.position.y) / _firework.startSpeed;
                // Calculate the horizontal speed of fireworks according to mouse click position and fireworks flight time;
                float x_v = (hit.point.x - gameObject.transform.position.x) / life_time;
                // Set the flight time of the particle just launched;
                m_Particles[0].lifetime = life_time;
                // Set the velocity of the particle just launched;
                m_Particles[0].velocity = new Vector3(x_v, m_Particles[0].velocity.y, m_Particles[0].velocity.z);
                // Apply the changes to the scene;_firework.SetParticles(m_Particles, count); }}}}Copy the code

๐ŸŽ Effect display

Hang the script to the scene and drag our fireworks effects to run!

The effect is as follows, the source project can be in the end of the small card reply [fireworks resources] to obtain oh.


๐Ÿ’ฌ summary

  • This article uses Unity’s particle system to make a simple fireworks special effect.
  • Look at the process is very much, in fact, this is physical work, there are artistic cells of the production of affirmation better look!
  • The size, color, flight path and so on of fireworks can be customized, after watching whether there is an impulse to make their own fireworks haha.
  • If you think it’s good, please feel free to like it and make a better one!!

Information white piao, technical mutual assistance

Learning Route Guide (Click to unlock) The knowledge orientation The crowd positioning
๐Ÿงก Unity system learning column ๐Ÿงก Entry level This column starts with learning how to get started with Unity, quickly reaching the beginner’s level of Unity
๐Ÿ’› Unity combat project ๐Ÿ’› In the class Plan to make 100 Unity cases in action! Help you enter the Unity world and strive to do the most complete Unity original blog.
โค๏ธ Game making column โค๏ธ The difficulty is on the high side Learn some Unity game demos and other languages!
๐Ÿ’š eighty thousand game enthusiasts community ๐Ÿ’š Help each other/blow water Eighty thousand game enthusiasts community, chat and mutual assistance, white piao prizes
๐Ÿ’™ Python from zero to getting started ๐Ÿ’™ Python beginners For those of you who have not been through systematic learning, the core purpose is to enable us to quickly learn Python to get started