The beam animates, but it lacks some punch. Let’s add particles on the firing point that look like sparkles.
Select the CastingParticles2D and add a Particles Material to it.
We want the particles to move in the direction of the beam. Expand the material, expand the Gravity category, and set the y
value to 0
.
In the Initial Velocity category, drag the Velocity slider to about 100
pixels per second. You can click on the value to set it manually.
The particles disappear abruptly. We are now going to make them fade out and scale down.
Find the Color category and assign a new Gradient to the Color Ramp property. We’re going to use it to fade out the particles.
Change the left color stop to an opaque white and drag it to two-thirds of the Gradient. Change the right color stop to a transparent white.
Under the Scale category, click on the Scale slot and set its value to 0.5
to decrease the particles’ default size.
Create a new Curve in the Scale Curve property. Drag the left point to about half of the curve’s horizontal axis and keep it at a value of 1
in the vertical axis.
Drag the rightmost point down to 0
.
This scale curve makes the particles disappear more naturally.
Finally, scroll back up the Inspector and toggle the Emitting property of the particle system off, so it doesn’t emit continuously.
Let’s add particles that spawn along with the laser.
We’re going to use a box emission shape and change its extents to match the Beam’s length. We are also going to make the particles swirl.
Select the BeamParticles2D node and head to the Inspector.
We want many particles, so set the Amount to 50
. We can randomize the time interval between two new particles increasing the Randomness to 1
.
In the Material property, create a new “ParticlesMaterial”. Change the Gravity and make sure it has a value of 0 in x
, y
, and z
to prevent the particles from falling.
In the Initial Velocity category, change the Velocity’s x
to -100
. to make the particles move towards the left, moving them slowly towards the beam’s origin.
Now, to make the particles swirl around the beam, expand the Tangential Acceleration category and change the Accel to 100
. Drag the Accel Random up to 1
to randomize the effect.
Next, find the Shape property under the Emission Shape category and change it to “Box”. In the Box Extents, set the y
value to 20
.
Let’s animate the particles to give them a more natural feel. Find the Scale property and change it to 0.3
. Create a new Curve in Scale Curve.
Drag both points in the scale curve to 0
on the vertical axis. Add a new point in the middle of the curve and drag it up to 1
vertically.
We have two more parameters to change on the particle system itself. Head back up out of the ParticlesMaterial and toggle off the Local Coordinates to keep the particles in place as the LaserBeam2D moves. Finally, change Draw order to “Life Time” to keep the newest particles on top of the older ones.
You should get a result looking like that:
Finally, let’s design the particles when the laser hits something. These particles are similar to the CastingParticles2D, so to be efficient, we are going to copy its material.
Select the CastingParticles2D node in the Scene tree. In the Inspector, right-click on the Material slot. From the drop-down menu, select the “Copy” option.
Select the CollisionParticles2D node. In the Inspector, right-click on the Material and select “Paste”.
From there, both CastingParticles2D and CollisionParticles2D are sharing the same ParticlesMaterial resource. They behave the same way, but changing the material on one node would apply the same change to the other. Sometimes, you want to share resources, but in our case, we do not.
To prevent that, we need to make the resource unique. Right-click on the ParticlesMaterial in the Material slot and from the drop-down menu, select “Make Unique”.
Now, we can modify the material of CollisionParticles2D without affecting that of CastingParticles2D. Let’s increase its Initial Velocity to make it spread more.
Increase the Amount property to 16
and set the particles’ Lifetime to 0.3
. Toggle off the Local Coordinates property, so the sparkles do not rotate with the laser. With that, you finished.
Here is the final result: