How to make a cannon!

A Tutorial for Left 4 Dead 2

An intermediate/advanced tut that will teach you how to create a shooting cannon

I don’t know if someone else did this in another easier way but this works for sure! If you’ll have any problem here's the vmf of the test map ;)
www.dropbox.com/s/rgpvwpvjv8o6len/Cannon_tut.vmf
This is the list of entities that will be used:
Prop_dynamic ; func_physbox (cannon ball); func_tracktrain (to let the cannon ball move)
Few path_track; trigger_multiple; env_explosion; env_shake; filter_activator_name; ambient_generic;
point_template; func_button .
*** Submitting this tut created a mess with "underscores", only few of them survived, most part of entities appears named without any underscore.. (like: trackcannonball or funcphysbox). Hope this won't create big problems, pay attention to match the names between all the entities!
Well, let’s begin
1] Create your own cannon with the Block Tool, for example I used the one in the screenshots and made it a func_detail. In the same way create the cannon ball, a good texture for the cannon and the ball is “wood/trimblack01”
For the cannon I’ve created a cylinder and then: “tools” -> “Make Hollow” -> 4
For the ball I used that strange shape cause Hammer doesn’t like spheres and sometimes removes them, don’t know why!
2] Now select the ball and press CONTROL+T, write func_physbox and press apply.
Give it a name (I’ll use cannon_ball) and set the strength to 0, material type: rocks, prop data: stone.small
Select from the flags: "start asleep" and "only break on trigger". Also write into parent: trackcannonball (look to the 4th point)
3] Now create a prop_dynamic and press world model, write button and choose a good one, then give it a name (button_cannon).
Place it where you want and surround it with a Nodraw block.
Select it and press CTRL+T -> func_button
Now you have to name it (for example: button_cannon_nodraw), make sure that the “use Activates” and “Don’t move” flags are set.
Also write into “Glow entity” : buttoncannon
Delay before reset: whatever you want, I wrote 15
4] This is the hardest part, if you’ll run into any bug about this send me the vmf and I’ll check it out ;)
Anyway, place a new nodraw block under the cannon ball and press CTRL+T, write func_tracktrain
(name: track_cannonball)
In its properties set the Initial Speed to 0 and Max Speed to 1000, set Height above tracks to 0, also make sure that the flag “Is unblockable by player” is set.
Into First Stop Target write: path1
Now place the ball and the track in the middle of the cannon, inside it. (3rd screen)
We have to create the path that the ball will follow, through the entity tool choose the path_track
(name: path_1) and place it into the nodraw tracktrain in the cannon. It’d be better to put the origin of path_track coinciding with the one of the Track.
Select the path_track and SHIFT DRAG it, Hammer will automatically create another one connected with the first. Put it at the end of the cannon. Repeat SHIFT DRAG again with the second and create the third.. Repeat till your trajectory is done, try to make it as realistic as possible! (I used 12 path_track in the example screen).
5] Create a point_template with the entity tool, name it template_cannon and in Template1 write: cannon_ball, Template2: track_cannonball. Place the template anywhere in the map.
6] Choose the ambient_generic entity and put it beside the cannon; Name: sound_cannon, SoundName: HulkZombie.ThrownProjectileHit
7] Go to the outputs window of your nodraw button and write the following outputs:
a) OnPressed; template_cannon; ForceSpawn; Delay: 0
b) OnPressed; cannon_ball; Wake; Delay: 0.01
c) OnPressed; track_cannonball; SetSpeed; “With a Parameter..” : 640 (it’s a good speed);
Delay 0.02
d) OnPressed; sound_cannon; Playsound; Delay 0.1
8] Now comes the trigger part.
Envolve the last path_track with a trigger block, CTRL+T and search for the trigger_multiple, here the name is not relevant.
Place anywhere you want a filter_activator_name, in “filter name” line write cannon_ball, name: filter_cannonball.
Go back to the trigger and write into “Filter Name” filtercannonball .
Start disabled: No
Flags: Physics object, Clients
Now let’s place few explosions and the env_shake.
9] Entity tool, search env_explosion and name it explosion_cannon, into magnitude line write the damage that you want (for example 500) and into radius something like 300.
Into flags check “Repeatable”.
Now copy the explosion and place 1 or 2 copies of it around the last path_track.
Go again to entity tool and search the env_shake. Place it above your trigger and name it shake_cannon.
Amplitude: 15, Radius: 500 (or whatever..), Frequency: 100, Duration: 1
10] Trigger outputs: On Start Touch
a) explosion_cannon; Explode; Delay: 0.2
b) shake_cannon; StartShake; Delay: 0.2
c) cannon_ball; Break; Delay: 0.2
d) shake_cannon; StopShake; Delay: 1.2
Last thing, select the last path_track, outputs:
a) OnPass; track_cannonball; Stop; Delay: 0
b) OnPass; track_cannonball; Kill; Delay: 0.5
This way everytime the tracktrain will reach the last path_track it will be removed from the map. So when the button is pressed again it will be spawned in the initial position by the point_template. The cannon ball breaks thanks to the trigger output and it spawns again when the button is pressed.
So you can shoot infinite times!
Enjoy :D
p.s. soon I'll upload a video of the working cannon :)