Making fireworks

We can make a firework effect just as easily as fire and smoke. Let's first think about how fireworks act. They fly into the air and instantly explode into hundreds of balls of light. Gravity takes over after the initial explosion, and as the balls of light fall back to earth, they fade out. We're going to make our particle system create hundreds of particles instantly, have those particles fly out from the center, be affected by gravity, and fade out. As for the flying into the air part, we will parent the particle system to a func_physbox entity and launch it into the air.

In Particle Editor, create a new particle system called firework01.

Creating the explosion

When creating particles, it's good practice to start with an emitter like we have done with the fire effect. Unlike the fire, however, we're going to use an emit_instantaneously property to create a bunch of particles at the same time. Change the num_to_emit value to 250 to create 250 particles instantaneously.

Creating the explosion

Just like before, the next step is to set up the renderer. Add a render_animated_sprites renderer and we can see that we have the familiar white square in our preview window. Also note that the particle count is 250/1004.

Creating the explosion

We haven't set up a decay yet, so everything is looking good so far with 250 live particles.

The next step is creating the explosion. We'll need an initializer property to create the initial movement, so in the Initializer tab, add a Velocity Random property. Set speed_in_local_coordinate_system_min to -250 -250 -250 and speed_in_local_coordinate_system_max to 250 250 250. This will create a random velocity between 0 and 250 units per second in every direction.

Our 3D preview isn't showing anything yet, because we still need a movement_basic operator to enable motion. Add one in to watch your little white boxes fly away.

Creating the explosion

Simulating gravity

We know that the pieces of fireworks fall because of gravity, so let's simulate that effect. While you still have the movement_basic property open, change gravity to 0 0 -100 and give the system a drag value of 0.05 to slow everything down. You should see the particles fire out from the center, slow to a crawl, and be pulled back down due to gravity.

Simulating gravity

Fading and other properties

While we're in the Operator tab, add in the alpha fade and decay properties. Leave everything to its default value, but set start_fade_out_time to 0.5 so that the particles begin fading out when they've lived 50 percent of their lives.

At this point, you will see the particles fade out predictably, but real fireworks don't do that; the sparks die out randomly. Add a lifetime random property in the Initializer tab and set the lifetime_min and lifetime_max fields to 1 and 2 respectively. Now it looks like we have the basics of a decent firework. Note the different alpha values of the particles.

Fading and other properties

Fireworks don't look like white boxes, so let's change the white box into a nice glow sprite and give the effect a burst of color. While we're still in the Initializer tab, add a color random property and pick two colors of your choice for color1 and color2. Each spawned particle will have a color somewhere between the two colors. Also add a Position Within a Sphere Random property with a radius_max value of 2. If this isn't done, the particle will always be created at the map's origin!

In the Properties tab of the particle effect, assign particle | particle_glow_10.vmt in the material field to get rid of that unsightly square.

Fading and other properties

Since we've already created a manifest file, we can call our firework particle complete.

A parenting example

We're going to create a firework entity set up using Hammer that will launch a Shell into the air, explode, and display our firework effect. We'll need the following entities:

  • Func_physbox
  • Phys_thruster
  • Phys_keepupright
  • Info_particle_system
  • Ambient_generic x 2

And, of course, we'll need func_button to set everything in motion.

A parenting example

Here's how it's going to work: the func_physbox entity will act as our firework Shell. It will be thrust into the air by a phys_thruster entity. Since we want a controlled ascent, we will use phys_keepupright to keep the Shell pointed straight up. The info_particle_system will display the firework effect in air, and the sounds will give us the launch and explosion ambience. Let's get to work!

Setting up the shell

The Shell is a func_physbox which is a brush entity. Create an eight-sided cylinder that has the dimensions 6 x 6 x 6 units. Tie it to a func_physbox entity and name it Shell. Nothing else needs to be done for the func_physbox entity.

Launching the shell

Create a phys_thruster point entity below the Shell and set the following properties:

  • Name: Shell_Thruster
  • Attached Object: Shell
  • Time of Force: 2
  • Force: 1000

Set angles to Up and make sure you check the Ignore Mass flag. The phys_thruster will apply an upwards force on the Shell for two seconds, thus launching it into the air.

Stabilizing the shell

Since the phys_thruster entity can be a bit unpredictable at times, we should stabilize the shell with phys_keepupright. Place one in the map near the shell and give it the following properties:

  • Target Entity: Shell
  • Angular Limit: 60

The Target Entity is the affected physics object; in our case, that would be the Shell. The Angular Limit specifies the maximum number of degrees per second that the phys_keepupright can correct the orientation of the shell by. We don't need to change the value of Angles for the phys_keepupright entity, because we never changed this for the shell. Since a value of 0 0 0 is considered to be upright, the phys_keepupright entity will try to maintain these angles.

Tip

Sixty degrees per second is a very safe Angular Limit value; this guarantees that our shell will stay vertical. Try experimenting with lower values to give your shell an unexpected wobble on the way up.

Setting up the particle

Place an info_particle_system entity on top of the shell.

Setting up the particle

Give it the following properties:

  • Name: Shell_particle
  • Parent: Shell
  • Particle System Name: firework01
  • Start Active: No

Since we've parented the particle system to the shell, wherever the shell goes, the particle system goes.

Adding sound effects

What's the fun of fireworks if they don't make any noise? Place two ambient_generic entities so we can emulate the launch and explosion sounds of a firework. Set the following properties for the first one:

  • Name: Shell_thrust_sound
  • Sound Name: rocketfire1.wav
  • SourceEntityName: Shell

This first ambient_generic entity is the sound we want to use when the shell is first launched; it's the same sound the Rocket Launcher weapon makes in Half-Life 2. The SourceEntityName will cause a sound to be emitted from the shell, making it more convincing.

The second ambient_generic entity should be set up as follows:

  • Name: Shell_explode_sound
  • Sound Name: explode4.wav
  • SourceEntityName: Shell

Tying everything together

In your func_button entity, add the following outputs:

OnIn, Shell_Thruster, Activate, 0.00s Delay
OnIn, Shell_Thrust_sound, PlaySound, 0.00s Delay
OnIn, Shell_Particle, Start, 2.50s Delay
OnIn, Shell_explode_sound, PlaySound, 2.50s Delay
OnIn, Shell_particle, ClearParent, 2.50s Delay
OnIn, Shell, Kill, 2.51s Delay
OnIn, Shell_Particle, Stop, 5.51s Delay
Tying everything together

The first two outputs activate the thruster and the sound effect as soon as the button is pushed. The third and fourth outputs will display the firework effect and play the sound. The fifth output clears the parent of the particle system, and the sixth output destroys the shell.

We clear the particle system's parent before killing the shell because if the parent dies, all its children die as well. If we didn't do this, the particle system would not display properly because its parent would be dead. The last output stops the particle effect after its maximum possible duration of three seconds.

Results

The following is what the setup looks like:

Results

The following is what the launch looks like:

Results

And the finale is shown as follows:

Results

We could have spent a few more minutes adding more fire effects to the rocket, tweaking the timings, and perfecting the particle systems, but this is a good start.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.61.170