Explosion effect - Particle System

Today I'm going to add a cool effect to the destruction of an enemy ship: we'll see a stylized explosion and a shaking of the screen.

The first thing I'm creating is the particle system that will simulate the explosion.

Particle Systems in Unreal Engine are made of one emitter (or more than one for complex animations) that will spawn particles with different sizes and velocities.
Particles can be sprites (simple 2D images that always face the camera) or meshes; I'm going to use sprites, so in Photoshop I'm creating a simple white blurred circle on black backgorund:



This will be the main shape of our particles. Remember that in Unreal Materials, when we use images for opacity, white means full opacity, while black is full transparent; so in this case we'll see a circle with transparent background.

After importing the texture in Unreal Engine as ExplosionTexture, we can create a new Material, called ExplosionMaterial. Let's define it as Additive and Default lit, so it can emit light.



I need a base color: I'm going to use the node Particle Color. This means that the material will take any color we'll choose for the particles, and use it. Obviously, we're going to use this materials with Particle Systems only, because without that information the material would not work properly.

I will use the Particle color for the Emissive Color as well, but I want to multiply it by a constant factor, because doing so the material will become more emissive and this will give our explosions a nice glow around them.



Now, I'm adding a TextureSample node and assign it to ExplosionTexture; once again, I'm multiplying it by another parameter given by the Particle System: Particle Opacity. This will allow me to fade the particle over time. We can connect the result to the Opacity pin of the material.



The material is ready; let's compile and save it, and create a new Particle System called ExplosionEmitter:

This gives us a simple system with one emitter; every emitter has a list of modules that define the settings of the spawned particles, like color, velocity, etc. We can edit the parameters of the default modules, or even add new ones or delete them.



In the "Required" module we can change the material of particles, and I'm choosing the ExplosionMaterial I just created.



Change the "Duration" to 0.5 and "Emitter loops" to 1: the default value 0 means it will loop forever, but we want it to only play once (scroll down to see these parameters).

In the "Initial size" module, I'll try with a minimum of 100 and a maximum of 200.



The default setup simulates something like a trial of smoke or a spray, with all particles going upwards. For our explosion, I want them to "explode" in all directions, so I'm moving to "Initial Velocity" module and change the values as follows:


(You may need to expand some sections if you don't see the fields shown above).

Since I want the particles to start with a high velocity that decreases when the particle is far from the emitter, I'll add another module: "Drag" (Right-click on the empty space under the modules > Acceleration > Drag).
I'll use a Distribution Float Constant and set it to 1.5; This will constantly decelerate the particles as they get away from the emitter.

Now the color: in the "Color Over Life" module I'll set the starting color ("Points" - "0") as a saturated yellow, and the ending color ("Points" - "1") as a darker orange-red.



In the same module we can also define the opacity: click on the graph icon in the module to show the curve envelope of the parameter in the lower half of the screen.

In this panel we can see how the parameters change in time. In the X axis, 0.00 is the emission time of the particle; 1.00 is the end of its life.

With CTRL + click we can add a point to the curve; I'll move this point to 0.8 in the X axis, and to 1.00 in the Y axis (full opacity). Then I'll create another point and move it to X = 1.00 and Y = 0.00 (fully transparent).


In the above graph you can also see the last parameter I added: in the "Size over life" I created 2 points, one at the X = 0.00 and one at X = 1.00, and I assigned them values 1 and 0 respectively. This will shrink the particles as they get far away from the origin.

You can also set the values of the ponts in the details panel on the left, as we did with the other parameters.

Now, the preview of the Particle Effect should show something like this:



It's time to trigger the explosion when a collision happens; in the Blueprint of EnemyBP we already have the Overlap Event, so we only need to chain a new function: search for "Spawn Particle System" and assign the Particle to ExplosionEmitter. A spawn location is required, and we can pass it the current enemy location:



That's all, let's see the final result:



In the next post we're going to enhance the effect by adding some camera shaking!
Game you next time!


Commenti