Setting up a basic razor train

From Valve Developer Community
Jump to: navigation, search
Trains

In this tutorial we are going to create a simple razor train with cars as seen in Half-Life 2; moving along a path on map spawn, playing the sound of a train horn when passing by one of the path nodes alongside its route. It is assumed the reader at this point in time has at minimum a basic understanding of how the hammer editor works.

Setting up

An example of a starting area.

To create a razor train in Hammer, you will use a prop_dynamic to parent these models to an invisible func_tracktrain brush:

  • props_combine\combinetrain01a.mdl (engine)
  • props_combine\combine_train02a.mdl (full carriage)
  • props_combine\combine_train02b.mdl (empty carriage)

Creating the train brush entity

The razor train engine and the world brush surrounding it.

Add a prop_dynamic using the model props_combine\combinetrain01a.mdl and create a standard world brush around it with the tools/invisible texture, this will be the actual func_tanktrain entity. Now, we are going to give the train model a name, Train_1 and we are also going to set the parent to RazorTrain, this shows up in red since we have yet to create the actual func_tanktrain entity. Once that is done, select the actual world brush, hit Ctrl + T and set the entity type to func_tanktrain. Now set the following values in the list for the tank brush entity:

Property Name Value
Name RazorTrain
Max Speed 1000
Initial Speed 700
Move Sound ambient/machines/razor_train_wheels_loop1.wav
First Stop Target path
The checked flags for the tank train entity.

You are also going to have to check the following flags as well:

  • No Pitch (X-rot)
  • No User Control
  • Passable
  • Fixed Orientation
  • HL1 Train

Creating the train tracks

Entity output for triggering the ambient_generic representing the horn of the train.

Now we are going to make the tracks the train is going to follow, so go right ahead select the Hammer entity.png entity tool from the sidebar and left click somewhere near the desired location of the track to create it, afterwards double click the entity and change its entity type to path_track. Position it right on top of the tracks and give it the name of path. Then all you have to do that is to hold Shift and move it along the tracks, which will automatically create and link additionally track entities.

Next create yet another entity, this time an ambient_generic with the name RazorTrainHorn and sound name value of ambient\alarms\razortrain_horn1.wav representing the razor train's horn. It might also be a good idea to set the value of SourceEntityName to that of the train entity, so that the location of the sound comes from the train's own location and not that of the ambient_generic entity. Set it up to be triggered by one of the path entities by going under the Output tab of the entity and create the following output, which will once the train passes its location tell it to play the razor train sound.

My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnPass RazorTrainHorn PlaySound <None> 0.00 No

Finishing up

The train entity with a locomotive and two train cars.
The finished product.

Now all there is left to do is to tell each path_track to go the speed you want and you are done. To add more cars, you can simply hold shift on your original prop_dynamic model like with the tracks and drag it to the position you want, change the name and leave it parented to the func_tanktrain entity, change the model and resize the block to fit the train's size. You will also have to remember to add a logic_auto is the train going to move on map spawn or instead a trigger_once if the player is supposed to trigger it when in a specific area.

Note.pngNote:Remember to wrap the func_tracktrain in a box, or your map won't compile because of the Leak
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnMapSpawn RazorTrain StartForward <None> 0.00 No

Notes

  • If you want a prop to behave as a train, parent it to an invisible func_tracktrain
  • Trains must be constructed facing east (in the Top viewport of Hammer, this is facing right). They will automatically align to the path in-game. If the train is not constructed facing east, it will not face the correct direction in-game.
  • You don't need to create each path_track by hand. Create the first one, then Shift-drag it to create another; the new one will be automatically linked from the previous one. This works even for inserting new path_track's between existing ones.
  • For Team Fortress 2 mappers: If you wish to duplicate the trains as seen in CP Well, it is necessary to parent a trigger_hurt to a func_tracktrain, as trains will not normally hurt on touch. To get the "killed by train" icon in the killbar, the damage type must be set to 'Train'.