Unity VFX -- (4) Create burst particle effects

        We can use a popping firework to motivate the user if they successfully reach a certain goal. If the character wields a sword, we can make a sword aura to increase the momentum. If the character falls to the ground, we can make flying dust on the feet to add expressiveness. These can be regarded as burst particle effects.

        The following are some examples of burst particle effects (burst particle). Since I couldn’t find a suitable translation, I will write the original English text of burst particle directly.

The muzzle spark effect when the weapon shoots

Flashing firework effect for players to celebrate when they reach the finish line

 Light and shadow when the user wields a weapon

        These event-based particle bursts are different from the previous environmental effects. They are burst effects of single particles triggered by specific events.

Add a new particle burst

        A burst particle is similar to an environmental particle, except that the burst particle does not last long and is usually generated in a smaller area. Let's start by adding a new particle system to the scene.

        1. In Heirarchy, right-click, select Effects -> Particle System, create a new particle system, rename it to "FX_SmokeBurst", then we set its position to X=0, Y=0.5, Z=0 and set The rotation is set to X=-90, Y=0, Z=0 (only the position in the case, it is actually placed on the fire, please move and rotate according to the actual situation).

        2. In the Particle System component of FX_SmodeBurst, expand the main module and uncheck the Looping attribute.

         After unchecking, the particles will stop playing immediately. After clicking Play in the Particle Effect window in the scene view, we will notice that the particle effect is generated for 5 seconds, and then stops. This is because the Duration attribute is set to 5. It seems to have a burst particle effect.

        In order to create a burst of particle effects, we lower the Duration to a small value (such as 0.05 seconds), and set the Rate over Time to a high value (such as 1000 particles per second), which will be in 0.05 seconds Generate 50 particles within (1000 * 0.05 = 50).

        But it seems that the effect is still not ideal, we still need to configure the Bursts option.

        3. In the Emission module, set Rate over Time to 0, which will prevent the particle system from generating particles over time.

        4. In the Emission module, click the "+" in the Bursts section to add a new burst.

         This default burst configuration means that at the 0th second (Time), the burst will generate 30 particles (Count) once (Cycles), and the probability is 100% (Probability). The Interval value currently has no effect because we only have one burst cycle.

Make particles move like smoke

        After using burst earlier, the particles move a little faster. Next we'll make them stay inside the fire.

        1. In the main module, reduce the Start Speed ​​property to 0.3 seconds.

        2. In the main module, reduce the Start Lifetime to about 1 second, and adjust this value according to our needs.

         Now that the speed issue is resolved, but the smoke looks like it's coming from outside the bottom of the fire, we need to modify the shape of the emitter.

        3. In the Shape module, change the Shape property from Cone to Sphere, then set the Radius to a value around 0.5.

        The particle movement looks correct so far, but since all the particles are moving at the same speed and disappearing at the same time, it doesn't look natural. We need to add a little randomness to the system to make the effect look more realistic.

Add a little randomness to the particles

         In the Inspector of the particle system component, we can see a small arrow behind many properties, and a drop-down menu will appear for us to choose after clicking. These drop-down menus provide additional options for setting values, including the ability to randomize parameters.

        In order to avoid particles spawning and disappearing at the same time, we can make the Start Lifetime a random value.

        1. Click the drop-down menu button of the Start Lifetime property and select Random Between Two Constants

        We will notice that this attribute now has two values, one is the minimum value and the other is the maximum value.

        2. Enter the minimum and maximum values ​​for Start Lifetime. For example, if the original Start Lifetime is 1, we can set it to 0.5 and 1.5, or 0.25 and 3.0. This value can be adjusted according to the actual effect after modification. Once complete, each particle in the particle system will have a different lifecycle.

        3. We can also perform similar operations on Start Speed ​​to randomize the speed of each particle in the particle system.

Edit Color over Lifetime with the Gradient editor

         In order to modify particles to change appearance during their lifetime, we need to enable some new modules.

        First of all, the appearance and disappearance of these particles is very abrupt, which seems strange. We can add some fade in and fade out effects.

        1. Select and enable the Color over Lifetime module, then expand it.

        2. In the Color over Lifetime module, select the white rectangular box to open the Gradient Editor window.

        The horizontal bar shows what the particle's color and opacity are during its lifetime, which starts on the left side of the bar and ends on the right. Therefore, by default, particles are white and opaque throughout their lifetime. We can use Gradient Editor to adjust the color and transparency of particles during their life cycle, as shown in the figure below, the blue fades in and the orange fades out.

         The markers above the color bar determine the transparency at different times, and the markers below determine the color change. For now we just need to make our example fade in at the beginning and fade out at the end.

        3. To make the particles fade in, select the marker in the upper left corner and set the Alpha value to 0.

        At this point the marker turns black, indicating that the color is completely transparent.

        At this point, we preview the actual effect of the example, and we will find that the particle changes from fully transparent to fully opaque during its life cycle. What we want is for the example to fade in quickly at the beginning and fade out slowly at the end. Let's adjust the arrow markers.

        4. Next, use the Gradient Editor to achieve your own fade-in and fade-out effect. To create a new transparency marker, simply select the empty space above the color bar, and to cancel a marker, move it up or down.

Edit Renderer and Texture Sheet Animation

         Next, we will adjust the texture of the particles. Now instead of simply replacing the default particle texture with another single texture, we use a texture sheet.

What are texture sheets

         There are some sub-images in a texture table, and these sub-images can be looped through to realize the effect of dynamic animation (each sub-image is similar to a key frame of an animation). As shown in the smoke effect in the picture above, there are four sub-pictures, and looping through them will have the effect of changing the shape of the smoke.

        We can use texture sheets to animate each particle.

Randomize the textures in the texture table

        First, we need to change the default particle material to one that includes a texture sheet.

        1. Expand the Renderer module, and in the Material property, select the texture sheet of SmodePuffMaterial.

        At this point, if we zoom in on the smoke in the scene view, we will find that each particle now shows the pattern of the entire texture sheet.

         In order to solve this problem, we need to enable the Texture Sheet Animation module, which allows us to cut the texture sheet into subgraphs and achieve animation effects.

        2. Enable and expand the Texture Sheet Animation module. We'll see a Tiles property that defines how many rows and columns the texture table has.

        3. In the Texture Sheet Animation module, set the Tiles property to X=2, Y=2, because the texture sheet we use has two rows and two columns.

        Click play again to see the effect.

         We can see that by default, Start Frame is 0, and Cycles is 1. This means that each particle will go through the four-frame submap of the texture table (starting from frame 0). While this is OK in some scenarios, it still looks a bit weird with smoke. So let's randomize the starting frame a bit.

        4. Change the Start Frame to Random Between Two Constants, and then set the minimum and maximum values ​​to 0 and 3. In this way, each particle will randomly select a frame as the start frame.

        5. Set Cycles to 0. After setting to 0, this value will be automatically changed to 0.0001, which will not affect the result.

        Preview to see how it looks

Use curves to change Size over Time

        Next we make the particles bigger when they appear and smaller when they disappear.

        1. Enable and expand the Size over Lifetime module, and select Curve in the Size drop-down menu.

        2. Select the curve preview box of the Size property. When selected, the lines inside will turn red.

        3. If we can't see the Particle System Curve window, just drag it up at the bottom of the Inspector. 

        After dragging it up, we can clearly see the curve graph.

        The horizontal axis of this graph represents time, and the vertical axis represents size

        The default curve is a straight line, which means that the particles grow linearly over time. At time 0, the size is 0 (the particle has just been generated), and at time 1, the size is 1, the maximum (at the end of the particle life cycle). 

Adjust Curve

        Now that we understand the layout of the particle system curve editor, let's edit the curve so that the particle size grows and shrinks over time.

        1. First, you can try the preset curves at the bottom of the particle system curve editor, and choose one of them to see the effect.

        The curve we want should be an inverted U-shaped curve (similar to a downward-opening parabola). We can know that the particles of this kind of curve will become larger and larger in the first period of time, and will become smaller and smaller in the later period. The default curve does not exist, so we need to customize it.

        2. Select the preset curve in the figure below as the initial curve

        3. Select and drag down the small red circle (keyframe) in the upper right corner, so that the Size of the end point of the curve becomes very small or 0

        If you preview, you will find that the particles become very small. This is because the maximum value of the curve is reached at about 0.3 seconds, and the apex of the curve is relatively low. We need to turn the curve up a bit.

        4. Select the keyframe at the bottom left, we will see a line next to the origin, and the line has an endpoint for adjustment.

        5. Drag the endpoint of the upper line and move it up to increase the height of the curve.

         Now let's look at the effect again. If we are not satisfied with the effect, we will continue to adjust the relevant module parameters of the particle system. For detailed information about the particle system module, please refer to the official documentation of Unity:

        Unity - Manual: Particle System modules

        For the prepared smoke effects, if you want to reuse them, you can make them into prefabs.

trigger animation

        Next, we use the script to detect the button and complete the effect of igniting and extinguishing the fire, and bring the smoke effect at the same time.

        1. In the main module of the particle system of the fire pile, make sure that Play on Awake is checked. This option can ensure that the flame particle effect can be played automatically when it is added to the scene.

        2. In the main module of the smoke particle effect, make sure Play on Awake is disabled (unchecked). We're going to use a script to trigger the timing of this special effect.

        After doing the above two steps, you can see that the flame will keep burning without the smoke effect.

        3. In the project window, drag the ToggleFireParticle script in the CreativeCore_VFX->Scripts directory to the Fire_ParticleSystem_Prefab object as its component.

        4. In the Inspector of Fire_ParticleSystem_Prefab, drag the corresponding Point Light (the sub-object of the prefab) and the smoke effect game object to the properties of the script.

        Click to run the scene, press the space bar to achieve the effect of ignition and extinguishment.

Guess you like

Origin blog.csdn.net/vivo01/article/details/130205496