[TUTORIAL] Trains, the easy way.

Spammish

L3: Member
Jan 2, 2010
117
34
While currently in the process of my first map I wanted a main feature to be 2 trains that pass through tunnels underneath the middle point. As I am still new to Hammer I found that doing it the "Valve" way seemed too complicated for myself and although looking through previous posts game me some help in this matter, nothing was relatively definitive and easy, but through a little logical thinking and trial and error I have found a quite easy way to achieve the same effect.
(Please note, on this first draft I am currently away from Hammer and so some details may not be exact, I may miss a step or two and there are currently no screenshots. When I can get back to Hammer I will provide screenshots, double check everything and rectify any mistakes.)

Step 1: Setting your path_track's

Choose the entity tool and place one entity where you want the start of your track to be, right-click>properties and under name call it something like 'Train1_path_a' then apply. Shift-drag this path_track to wherever you want your track to end and a line should appear joining the two path_track's, go to the end path_track's properties and set it's next path_track to your start path track. Go back to your first path track, then to properties, then click the flags tab and select 'Teleport to THIS path_track', this should be the only box ticked. Your path_track's now await their accompanying train.

step1.JPG


Step 2: Setting up your train

Spawn another entity near to your starting path_track (this is purely for organisation) and change it to a prop_dynamic, naming isn't necessary, and choose "train_enginecar" then apply. Create a nodraw brush roughly the size of the of the train and press CTRL+T, change it into a func_tracktrain, name it something such as 'Train1', set its first path track to your starting path track, in our case that's 'Train1_path_a and the set whatever speed you like, for reference, the train in well uses 1024. Go back onto properties for your prop_dynamic train and set its parent to your func_tracktrain's name, 'Train1' in our case.

Step2.JPG


Step 3: The (slightly) technical part

Spawn another entity and change it to a logic_timer, for more complicated systems you may need to name the timer and it doesn't hurt to do this even if you're not, make sure start disable is no and if you wish for random timing (as all trains in TF2, that I know of, use) then select random timing as yes, input your desired minimum and maximum interval time then select the outputs tab. Add a new output and make it so that it is Ontimer, 'Train1' Start forward. Then select your ending path_track and go to the output tab, add a new output and make it so that it is, Onpass, 'Train1', Stop.

Step3a.JPG

Step3b.JPG


You should now have simple train that moves at random times within your set boundaries.
The guide will now be broke up into sections as although they may be important they aren't necessarily needed.
Now for the interesting part :D
Trigger_hurt

Choose the trigger texture and create a box around the front of your train, this is the area which will kill you if touched. Ctrl+T and change it to a "trigger_hurt", set it's parent to the name of your func_tracktrain, which in our case is Train1, set it's damage to something high like 1000 for instant kills and change the damage type to train so that any sacrifices to the train god will be known to all (e.g. kill icon will show the train symbol :p)

Trigger_hurt.JPG

Your train is now a train god.

Moving train sound

Spawn an entity and change it to an ambient_generic, place it near or in your train for organisations sake and go onto properties, name it something like Train1_moving_sound, set it's SourceEntityName to the name of your train, Train1 in this case and set the sound name to "Ambient.Train". Apply this and then go to your logic_timer, add a new output and make it; Ontimer, train1_moving_sound, PlaySound and apply, then go to your ending path track and add a new output, make it; OnPass, train1_moving_sound, StopSound. You now have no excuse not to move out of the way of the train god.

Train_sounds.JPG

Train_sounds2.JPG

Train_sounds3.JPG


Prefab here: http://forums.tf2maps.net/downloads.php?do=file&id=3186 , although you should learn how to make them on your own anyway :p
If anyone has any suggestions or wants something specific, just ask and I'll do my best to help.
 
Last edited:

Bob Ross

L3: Member
Jun 16, 2009
105
9
this will be helpful. thanks.

oh and dont forget the best part: the trigger_hurt :D
 

Tapp

L10: Glamorous Member
Jan 26, 2009
776
215
May I recommend adding the part about well's trains, how they transition from the 3d skybox into the game, that can be quite tricky to do. But by copying well, you can have trains which seem to approach from miles away, without being too expensive.
 

Spammish

L3: Member
Jan 2, 2010
117
34
I may try to simplify that from what I can make out from Valve, my main problem with copy-pasting from well (what I did at first) was all the other logics which supposedly made it more random somehow by having a logic_case to randomly choose whether or not to fire the train on the timer, as well as the door opening logic_relays (which I plan to cover). I may be able to create a rudimentary system that is much simpler than Valves simply by setting the logic_timer to fire the skybox train and then setting that to fire the actual train when it passes a certain path_track, thanks for the suggestion, I'll have a look into it over the next few days :D
 

Tehrasha

L3: Member
Nov 5, 2009
115
28
Well done. Works for me... mostly.

A minor tweak... Step 2 says to name the prop, then later references the func_tracktrain as the named entity. The latter is correct, the prop needs no name.

My first train map (thanks to your Tut.) has two trains on separate tracks, running merrily along. The only glitch I have is that they start out half buried in the track, and slowly emerge as they travel, as if the path_track was up hill... which it isnt.
 

Spammish

L3: Member
Jan 2, 2010
117
34
Thanks for that correction, didn't notice it when I skimmed through :thumbup: As for your problem, are you sure both path tracks are on the same height plane? If they are, does the prefab I created work? If none of this works, can you post a .bsp and .vmf and I'll give it a look over, if the prefab doesn't work it must be a problem with your map.
 

Gearloose

L1: Registered
Nov 6, 2008
2
0
There's an easier way to do the sound - just set the Move Sound property of the func_tracktrain brush to the train sound effect, and set the two pitch values to 100.

You'll still want to add other sound entities if you want to activate railroad crossing bells etc.

Thanks for the tutorial BTW - it helped me out.
 

Tehrasha

L3: Member
Nov 5, 2009
115
28
If they are, does the prefab I created work? If none of this works, can you post a .bsp and .vmf and I'll give it a look over, if the prefab doesn't work it must be a problem with your map.

Your prefab does work for me (though the trigger_hurt isnt parented to the func_train).
The train stays level no mater how long I make the track.

Will look at mine again tonight and get you a .vmf if it still a problem.

On multiple cars::
If I remember correctly, you just place as many cars as you like, and then parent them to your func_tracktrain.

This should work perfectly, provided the train doesnt make any turns. (very few maps do) Otherwise the end cars will be swinging out in a wide arc behind the train while the engine pivots. :)

Additional::
Does anyone know if you can make different trains travel down one track? I know the timing can be done with multiple logic timers, but can the train be picked at random?

example:
train1 ----->
*random delay*
train1 ----->
*random delay*
train2 <-----
*random delay*
train1 ----->
*random delay*
train3 <----- very fast
*random delay*
etc..etc..
 
Last edited:

Spammish

L3: Member
Jan 2, 2010
117
34
It would be possible, it'd just basically involve putting the workings of 3 trains and their path and logics all into the same place with different starting points, quite simple really just a little laborious.
Edit: Just saw the trains at random bit, something similar to this is used on valves train setup but I can't remember the name, I think it's something like logic_case, though I'm not sure, I'll have a look into it.
 

wyn10

L1: Registered
Nov 22, 2009
46
3
God for the life of me can't get this working.


It just sits there..Even the prefab just sits there for me.

Someone make a test map for this?
 
Last edited:

Tehrasha

L3: Member
Nov 5, 2009
115
28
God for the life of me can't get this working.
It just sits there..Even the prefab just sits there for me.

I thought the prefab was broken at first as well, but it just has really long delays for a proof of concept. Change the min delay to 5 sec and max to 15 sec. Gets alot busier. :)


EDIT: After I fiddled with the origins and made sure the trains were at exactly the right height, they look fine now. I think I was only seeing an optical illusion that made them look farther above the tracks as they got further away.
 
Last edited:

Spammish

L3: Member
Jan 2, 2010
117
34
Ah, its almost always something simple :p good luck on the rest of your map. And ye, the timer is quite long but I set it like that so that if you wanted to could just plop it into your map and not have to adjust if you didn't want.