WiseTrains4: HL2 Trains and Complex paths
This tutorial was originally created by wisemx. It was originally posted on SDKnuts.net.
Introduction
In this project:
- Player gets on a train.
- Train doors close.
- Starts forward then stops once it clears a building.
- Begins to lower, slowly, then stops.
- Resumes backward, slowly, and then stops once inside the building.
- Lowers again but this time down, sub-ground level.
- Train stops and the front door lowers to create a ramp to another train.
- Player walks onto second train which starts forward and continues to loop underground.
Concept
This type of train was a common effect in Half-Life. Most everything used for this sort of player vehicle was born in HL1. There is an additional effect I wanted to incorporate into this tutorial and I’ve been bugging several of the Developers at Valve for months but haven’t gotten them to talk yet. I’ve been trying to get the HL1 legacy entity func_trackautochange
working in HL2.
The SDK code for it seems good and I can get it to return an error when it should but it refuses to work as it should. (Porter's note: There's not really a reason to use func_trackautochange
in Source, certainly not for this project, at least.)
A feature I added to this train, because I’ve received so many questions about things like this, is a func_rot_button
parented to the func_tracktrain
. The front door on the train, which later becomes a ramp for the player, is a func_rot_button
. (Porter's note: Also consider func_door_rotating
.) Remember the HL2 coast yellow-striped roadblocks that pop up out of the road? Those are func_rot_button
, a handy entity for buttons, levers or a door and it can be made to move in any direction.
Connecting trains like this can really liven up your HL2 map. Bringing trains into HL2, coupled with the buggy and airboat, is a recipe for success. (Porter's note: Vehicles can get boring too, though.) The trains in this project are brush based, as is the train you ride in HL2. I didn’t create rails for these trains because they simply serve for appearance. The rails, in your HL2 maps, can be created from props, brushes or entities like env_beam
and ropes.
The main difference between the two trains in this project is their Change angles property. For the first train Change angles is Never (fixed orientation). For the second, looping, train its: Near path_tracks.
Your options are:
- Never (fixed orientation) - Train will remain in position as it moves.
- Near path_tracks - Train orientates itself at path_tracks.
- Linear blend - Orientates between path_tracks.
- Ease in/ease out - Orientates between path_tracks, Swan-like movement.
You will probably always use either Fixed or Near for your Change angles. Using either of the other two settings for Trains will make them look like they’re on ice. Another important thing to consider is the length of your train and the func_tracktrain
property Distance Between the Wheels. If your trains are short this number should be smaller, but a train that is longer than 100 units, for example, will look odd if the Distance Between the Wheels property is set low. If you can’t picture how this makes a difference try to imagine your train coming around a corner, think of the front and tail sections of the train. When the number is smaller your train will whip through corners rather quickly, which is why it will look odd on a longer train.
There are also important properties on the path_track
s that you can change.
- Select a
path_track
and zoom in on it in the top (x/y) 2D viewport, then press Alt+↵ Enter to open the properties window. Notice the yellow indicator line on top of it? This is the direction for thatpath_track
. When thepath_track
property Orientation Type is set to Face thispath_track
s angles it will control the train unless the train is set to ignore orientation changes. - The
path_track
property New Train Speed can be used to alter the trains speed when it reaches thatpath_track
. You can also use the outputs from thepath_track
to change the train's speed. - Branch Path can be used for alternate paths. See WiseAltPath.
- The flags for each
path_track
have a lot of control over the train.
- Disabled (Will be ignored.)
- Fire once (Only used one time.)
- Branch Reserve (Alternative.)
- Disable Train (Train will stop functioning.)
- Teleport to THIS path_track (Train will jump to, or start at.)
See also
- Example VMF
- Example VMF backup
- WiseTrains: Player Controllable Trains
- WiseTrains2: Automated Trains
- WiseTrains3: HL2 Synchronized Trains
- WiseTrains4: HL2 Trains and Complex paths