Laser beams
As promised, here is the tutorial about creating laser beams with Torque Game Builder. The laser beam effect I created is different from the type you commonly see in games or movies. Instead of a spear-like beam, the entire beam appears at once. The only time I had ever seen something similar in another game was the Obelisk of Light in Command & Conquer. But let’s get started. First of all, the particle sprite. This is a pretty straightforward one, just a blurred white dot.

Create a new emitter, select the sprite and apply the following settings to the emitter:
Some explanation. The emitter type is set to LineY, wich means the particles are emitted along a vertical line. In all previous tutorials, this was a point. The aspect ratio is no longer fixed, so the particles can be stretched. This is necessary to make them overlap into a solid beam. Next, the graph properties.
The particle life is set to 1. The quantity is a bit more complicated. For the first 0.25 seconds, 1000 particles per second are emitted, wich then drops to zero at 0.75 seconds. This creates a short particle burst.
The base sizes are set to 15 (X size) and 40 (Y size). The “Size Y Life” field is what turns the particles into a more or less solid beam. Over the course of the particle life, they get stretched vertically to three times their size. The Y-size goes from 1 to 3 in a second.
Ignore the fields for speed, spin, fixed force, random motion, emission force, emission angle and emission arc. These are all set to zero, making the particles stationary. Color settings are pretty simple. Red is set to 1.0 and both blue and green to 0.2.
And finally, the visibility. From 0 to 0.25 seconds, the effect is fully visible and then rapidly drops to zero. Experiment a bit with this to get the effect you want. If you make it fade away slower, the beam will have a more glowing effect.
The effect you have created now is aimed at a vertical size of 768 pixels. Changing the length of it will change the appearance, because more particles will be created in less space, making the beam look denser. This can be solved with a little bit of code:
%Emitter = %this.Laser.getEmitterObject(”Beam”);
%Emitter.selectGraph(”quantity_base”);
%Emitter.setValueScale(%this.Laser.getHeight()/768);
What happens here? The first line selects the particle emitter “Beam” in the particle effect “Laser”. Next, the graph “quantity_base” is selected. All the following operations on graph fields will now be applied to this graph. Finally, the ratio of the current height to the original height is calculated and the amount of particles is scaled accordingly. So, if the height of the beam is reduced by 50%, so will the amount of particles, and the beam will still look the same!
If you want to experiment with this yourself, you can download the effect and particle sprite.

Leave a Reply