WiseAltpath: Alternate paths

From Valve Developer Community
Jump to: navigation, search


This tutorial was originally created by wisemx. It was originally posted on SDKnuts.net.

When using func_tracktrain on path_track's it’s often handy to have an alternative path. Imagine a train that is on a track, the player has to stop the train and push a button, then once back on the train it follows another set of tracks.

In this project I’ve used a Roller_Spikes.mdl parented to a func_tracktrain. The roller will follow a triangular path on the left side of the screen for 3 loops. It will then switch to a triangle on the right side for three loops. This will continue indefinitely.

This is down with 5 path_track entities with one of them acting as a track switch. I’m using a math_counter to change the track but the very same effect can be achieved with triggers, buttons, etc. When the map loads the train will be moving from the start. Each time it passes switch01 I’m adding a value to a math_counter. When the math_counter gets to 3 it will switch the track.

Note.pngNote:Please refer to my series of WiseTrains tutorials on HL2 trains for specific information about properties for tracks and trains.

Give each of the path_track entities a name that reflects their role. This helps as you are working on your map.

The math_counter:

  • Name: math01
  • Initial value: 0
  • Min legal value: 0
  • Max legal value: 3
  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnHitMax switch01 ToggleAlternatePath 0.00 No
Io11.png OnHitMax math01 Subtract 3 0.50 No

The path_track, switch01:

  • Next stop target: path_a1
  • Branch Path: path_b1
  My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnPass math01 Add 1 0.00 No

When the train gets to path_track switch01 an output will add the value 1 to the math_counter.

When the math_counter gets to 3 it will fire an output to ToggleAlternatePath which will instantly change the train to the alternate path.