This article's documentation is for anything that uses the Source engine. Click here for more information.

Func tracktrain: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (→‎Keyvalues: Explained how distance between wheels works.)
m (Substituted IO templates)
 
(31 intermediate revisions by 19 users not shown)
Line 1: Line 1:
{{base brush|func_tracktrain}} It functions as a moving platform that the player can ride. It follows a path of [[path_track]] entities.
{{distinguish|func_tanktrain}}
{{tip|Increase the '''Distance Between the Wheels''' keyvalue for smoother turns.}}
{{tabs|func tracktrain|goldsrc = 1|source = 1|main = source}}
{{CD|CFuncTrackTrain|file1=trains.cpp}}
{{this is a|brush entity|name=func_tracktrain}} It functions as a moving platform that the player can ride. It follows a path of {{Ent|path_track}} entities.


{{note|Unless the ''Fixed Orientation'' flag is set, build your train so that the front of the train is facing down the X axis. (This means that the front of the train is visible in the front view, etc..) When it spawns it will automatically rotate to face the next <code>path_track</code> on the path.}}
{{note|Unless the <code>Fixed Orientation</code> flag is set, build your train so that the front of the train is facing down the X axis. (This means that the front of the train is visible in the front view, etc.) When it spawns it will automatically rotate to face the next <code>path_track</code> on the path.}}
 
{{note|Tracktrains only update their movement direction 10 times per second. At higher speeds, this can result in them overshooting the track, especially with sharp turns. The older {{ent|func_train}} entity is not affected by this issue, so it may be a suitable alternative for high-speed objects.}}
=== Individual keyvalues and flags ===
{{bug|Due to poor coding, the <code>Reverse</code> and <code>StartBackward</code> may not function correctly if the <code>New Train Speed</code> property in the involved {{ent|path_track}} entities is set to 0. The train may fail to reverse, jamming in place or moving in the wrong direction. To solve this issue, some or all of the <code>path_tracks</code> must have their <code>New Train Speed</code> variable set to a non-zero value.}}
{{TODO|Since the keyvalues and flags are currently templated to multiple entities, the individual data for this entity is written in this section until all the other entities having these templates has been researched (and found either similar or diverse).}}
{{bug|Trains stop short at a distance from their targets, regardless of speed. The higher the speed, the further away it will stop from the path_track. At low speeds, this is negligible.}}
 
*'''orientationtype'''
:<choices> How/If the train should change its angles as it travels.
:{| class=standard-table
! Literal value || Description || Effect
|-
| 0 || Never (fixed orientation) || The orientation of the train is fixed (instead of being relative to the direction of the track) permanently facing the direction it was ''spawned'' in (according to the direction of the first track). This overrides the ''Orientation Type'' settings of its <code>path_track</code>. Does not turn around when reversing direction.
|-
| 1 || Near path_tracks || The train changes direction upon nearing a path_track. Does not turn around when reversing direction.
 
|-
| 2 || Linear blend || Very weird orientation that is choppy in corners. (Please find a use for it.) Turns around when reversing direction.
|-
| 3 || Ease in/ease out || Seemingly the same orientation as ''Linear blend'' (a little less choppy). Turns around when reversing direction.
|}
 
* 16 : Fixed Orientation - The orientation of the train is fixed (instead of being relative to the direction of the track) permanently facing the direction it was ''created'' in (prior to spawn). Overrides both the "Change angles" keyvalue setting of this <code>func_tracktrain</code>, and the ''Orientation Type'' settings of its <code>path_tracks</code>.
 
* 128 : HL1 Train - Set this flag if you want the player to be able to ride on or in a train while it is moving rapidly, or accelerating. Not setting this flag will cause the player to be knocked off the train (and take blocking damage, if set) when he bumps into collision surfaces parented to it.
 
<!-- dead links
== See also ==
* [http://sdknuts.net/akg/tutorials/wiseElevators.asp HL2 Elevators]
* [http://sdknuts.net/akg/tutorials/wiseLaser.asp Moving Laser]
* [http://sdknuts.net/akg/tutorials/wiseTrains.asp Player Controllable Trains]
* [http://sdknuts.net/akg/tutorials/wiseTrains2.asp HL2 Automated Trains]
* [http://sdknuts.net/akg/tutorials/wiseTrains3.asp HL2 Synchronized Trains]
* [http://sdknuts.net/akg/tutorials/wiseTrains4.asp HL2 Trains and Complex paths]
* [http://sdknuts.net/akg/tutorials/wiseAltpath.asp Alternate paths]
-->
 
{{in code|class=class_c_func_track_train.html CFuncTrackTrain|file=trains_8cpp-source.html trains.cpp}}


== Keyvalues ==
== Keyvalues ==
{{KV BaseTrain}}
{{KV Targetname}}
{{KV|First Stop Target|intn=target|target_destination|The name of the first <code>path_track</code> in the train's path. The train will spawn at this <code>path_track</code>. It will also turn to face the direction indicated by the "Orientation Type" setting.}}
{{KV|Max Speed (units/second)|intn=startspeed|integer|The maximum speed that this train can move. Any speeds applied to this train, such as by <code style{{=}}padding:0>path_track</code>s or <code>SetSpeed</code> inputs, will be clipped to this maximum value.}}
{{KV|Initial Speed (units/second)|intn=speed|integer|The speed that the train will move at after it spawns, 0 {{=}} stopped.}}
{{KV|Change Velocity|intn=velocitytype|choices|The method through which this train changes its velocity as it moves along the path.}}
:* 0 : Instantaneously
:* 1 : Linear blend
:* 2 : Ease in/ease out
{{KV|Change angles|intn=orientationtype|choices|The method through which this train changes its orientation as it moves along the path.}}
:* 0 : Never (always fixed orientation)
:* 1 : Near paths
:* 2 : Linear blend
:* 3 : Ease in/ease out
{{KV|Distance Between the Wheels|intn=wheels|integer|Used for turning and stopping.}}
:{{tip|Increase the value for smoother turns.}}
{{KV|Height above track|intn=height|int|The height above the track that this train moves.}}
{{bug|If a train using this setting gets teleported to a <code>path_track</code>, its will teleport <i>directly</i> to the path. This will result in the train traveling an extended distance towards its next path to reach the desired height again.|only=|tested=TF2}}
{{KV|Bank Angle on Turns|intn=bank|string|The angle at which the train will "bank" or tilt when approaching a turn. Use positive or negative angle numbers close to 0 (i.e., between -5 and +5, depending on left or right) to achieve realistic tilt angles.}}
{{KV|Damage on Crush|intn=dmg|int|The amount of damage this train does to entities that block it.}}
{{KV|Minimum Light Level|intn=_minlight|string|The minimum level of ambient light that hits this brush.}}
{{KV|Move Sound|intn=MoveSound|sound|A sound that is played (and looped) while the train is moving.}}
{{KV|Move Ping Sound|intn=MovePingSound|sound|A sound that is played more frequently as the train speeds up.}}
{{KV|Start Sound|intn=StartSound|sound|A sound played when the train starts moving.}}
{{KV|Stop Sound|intn=StopSound|sound|A sound played when the train stops moving.}}
{{KV|Volume (10 {{=}} loudest)|intn=volume|integer|Volume of the sound when the train is moving.}}
{{KV|Min pitch (1-255, 100 {{=}} normal)|intn=MoveSoundMinPitch|int|The sound pitch value that the train will approach as it comes to a stop.}}
{{KV|Max pitch (1-255, 100 {{=}} normal)|intn=MoveSoundMaxPitch|int|The sound pitch value that the train will approach as it approaches its max speed (or 1000 inches/second if the "Use max speed for pitch shifting move sound" flag is not set).}}
{{KV|Min move sound interval|intn=MoveSoundMinTime|float|Minimum interval at which to play the move ping sound.}}
{{KV|Max move sound interval|intn=MoveSoundMaxTime|float|Maximum interval at which to play the move ping sound.}}
{{KV|Manual Train Speed|intn=manualspeedchanges|boolean|Train Speed is controlled through IO, handles accel, decel times.}}
{{KV|Manual Accel Speed|intn=manualaccelspeed|float|Units per second to accelerate to target speed.}}
{{KV|Manual Decel Speed|intn=manualdecelspeed|float|Units per second to decelerate to target speed.}}
{{note|The above three keyvalues are {{Not in FGD}} in Left 4 Dead and later, but appear to still exist in the engine.}}


Distance between wheels is the distance in Hammer Units between the front axle and rear axle of your train. The rear axle moves the train and stays on the track. The front axle turns as it approaches path_tracks and does not stay on the track.
Distance between wheels is the distance in Hammer Units between the front axle and rear axle of your train. The rear axle moves the train and stays on the track. The front axle turns as it approaches path_tracks and does not stay on the track.


== Flags ==
== Flags ==
{{Fl BaseTrain}}
{{fl|1|No Pitch (X-rot)}}
{{fl|2|No User Control}}
{{fl|4|Forward Only|Controlling player may only move the entity forward, or stop it.|nofgd=1}}
{{fl|8|Passable|Disables collisions on the object.}}
{{fl|16|Always Fixed Orientation}}
{{fl|128|{{Hover info|HL1 Train|Rideable Train|line=dashed}}|Does not knock entities off or cause damage.}}
{{fl|256|Use max speed for pitch shifting move sound}}
{{fl|512|Not blockable by players}}


== Inputs ==
== Inputs ==
{{I BaseTrain}}
{{I|SetSpeed|Set the speed of the train, as a ratio of max speed [0, 1]|param=float}}
{{I|SetSpeedDir|Set the speed of the train, as a ratio of max speed. Negative values reverse the direction [-1, 1]|param=float}}
{{I|SetSpeedReal|Set the speed of the train. Must be a positive value from 0 to max speed.|param=float}}
{{I|SetSpeedDirAccel|Accel/Decel to the specified speed, as a ratio of max speed. Negative values reverse the direction [-1, 1]|param=float|not={{l4d}}}}
{{I|SetSpeedForwardModifier|Applies the given modifier to all forward speeds. [0, 1]|param=float|removed={{l4d}}}}
{{I|TeleportToPathTrack|Teleport the train to the designated path track. This can be in a new path.|param=targetname|removed={{l4d}}}}
:{{note|The above three inputs appear to have been added to [[Source 2007]] games post-release for TF2's Payload mode, but did not make it into later games, resulting in their apparent "removal". However, <code>SetSpeedDirAccel</code> did later get ported in {{l4d2|4}}.}}
{{I|MoveToPathNode|Move the train to a specific path_track, stopping when it gets there. Must be in the same path.|param=targetname|since={{portal2}}}}
{{I|TeleportToPathNode|Teleport to another path_track and stop the train. This can be in a new path.|param=targetname|since={{portal2}}}}
{{I|LockOrientation|Lock the current orientation of the train.|since={{portal2}}}}
{{I|UnlockOrientation|Unlock the current orientation of the train.|since={{portal2}}}}
{{I|SetMaxSpeed|Set a new max speed for the train.|param=float|since={{portal2}}}}
{{I|Stop|Stop the train.}}
{{I|StartForward|Start the train moving forward.}}
{{I|StartBackward|Start the train moving backward.}}
:{{bug|If the train's corresponding [[path_track]]s do not have "New Train Speed" set to a nonzero number, StartBackward will exhibit undesired behavior including the train freezing or moving in the wrong direction. This bug can be a pain if the train needs to ride through the path_track again at a different speed. This can be fixed by firing an "addOutput speed '#'" input at the path_track in question.}}
{{I|Resume|Resume the train moving in the current direction after it was stopped via the <code>Stop</code> or <code>Toggle</code> input.}}
{{I|Reverse|Reverse the direction of the train.}}
{{I|Toggle|Toggle the train between start and stop.}}


=== Backward movement ===
== Outputs ==
Due to coding errors or engine limitations, the ''Reverse'' and ''StartBackward'' may not function correctly if the "New Train Speed" property in the involved '''[[path_track]]''' entities is set to 0. The train may fail to reverse, jamming in place or moving in the wrong direction. To solve this issue, some or all of the <code>path_tracks</code> must have their "New Train Speed" variable set to a nonzero value.
{{O|OnStart|Fired when the train starts moving in either direction.}}
{{O|OnNextPoint|Fires continuously every tick when the train is currently moving to its next destination.|nofgd=1}}
:{{warning|In the default FGD, this is incorrectly listed as "OnNext" and has an incorrect description ''("Fires when this train picks a new point to move towards (and just after OnStart)")''}}
{{O|OnArrivedAtDestinationNode|Fired when this train arrives at a destination that was specified by the MoveToPathNode input.|since={{portal2}}}}


== Outputs ==
== See also ==
{{O BaseTrain}}
* {{ent|func_traincontrols}}

Latest revision as of 21:46, 19 April 2025

Not to be confused with func_tanktrain.
C++ Class hierarchy
CFuncTrackTrain
CBaseEntity
C++ trains.cpp

func_tracktrain is a brush entity available in all Source Source games. It functions as a moving platform that the player can ride. It follows a path of path_track entities.

Note.pngNote:Unless the Fixed Orientation flag is set, build your train so that the front of the train is facing down the X axis. (This means that the front of the train is visible in the front view, etc.) When it spawns it will automatically rotate to face the next path_track on the path.
Note.pngNote:Tracktrains only update their movement direction 10 times per second. At higher speeds, this can result in them overshooting the track, especially with sharp turns. The older func_train entity is not affected by this issue, so it may be a suitable alternative for high-speed objects.
Icon-Bug.pngBug:Due to poor coding, the Reverse and StartBackward may not function correctly if the New Train Speed property in the involved path_track entities is set to 0. The train may fail to reverse, jamming in place or moving in the wrong direction. To solve this issue, some or all of the path_tracks must have their New Train Speed variable set to a non-zero value.  [todo tested in ?]
Icon-Bug.pngBug:Trains stop short at a distance from their targets, regardless of speed. The higher the speed, the further away it will stop from the path_track. At low speeds, this is negligible.  [todo tested in ?]

Keyvalues

Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

First Stop Target (target) <targetname>
The name of the first path_track in the train's path. The train will spawn at this path_track. It will also turn to face the direction indicated by the "Orientation Type" setting.
Max Speed (units/second) (startspeed) <integer>
The maximum speed that this train can move. Any speeds applied to this train, such as by path_tracks or SetSpeed inputs, will be clipped to this maximum value.
Initial Speed (units/second) (speed) <integer>
The speed that the train will move at after it spawns, 0 = stopped.
Change Velocity (velocitytype) <choices>
The method through which this train changes its velocity as it moves along the path.
  • 0 : Instantaneously
  • 1 : Linear blend
  • 2 : Ease in/ease out
Change angles (orientationtype) <choices>
The method through which this train changes its orientation as it moves along the path.
  • 0 : Never (always fixed orientation)
  • 1 : Near paths
  • 2 : Linear blend
  • 3 : Ease in/ease out
Distance Between the Wheels (wheels) <integer>
Used for turning and stopping.
Tip.pngTip:Increase the value for smoother turns.
Height above track (height) <integer>
The height above the track that this train moves.
Icon-Bug.pngBug:If a train using this setting gets teleported to a path_track, its will teleport directly to the path. This will result in the train traveling an extended distance towards its next path to reach the desired height again.  (tested in: TF2)
Bank Angle on Turns (bank) <string>
The angle at which the train will "bank" or tilt when approaching a turn. Use positive or negative angle numbers close to 0 (i.e., between -5 and +5, depending on left or right) to achieve realistic tilt angles.
Damage on Crush (dmg) <integer>
The amount of damage this train does to entities that block it.
Minimum Light Level (_minlight) <string>
The minimum level of ambient light that hits this brush.
Move Sound (MoveSound) <sound>
A sound that is played (and looped) while the train is moving.
Move Ping Sound (MovePingSound) <sound>
A sound that is played more frequently as the train speeds up.
Start Sound (StartSound) <sound>
A sound played when the train starts moving.
Stop Sound (StopSound) <sound>
A sound played when the train stops moving.
Volume (10 = loudest) (volume) <integer>
Volume of the sound when the train is moving.
Min pitch (1-255, 100 = normal) (MoveSoundMinPitch) <integer>
The sound pitch value that the train will approach as it comes to a stop.
Max pitch (1-255, 100 = normal) (MoveSoundMaxPitch) <integer>
The sound pitch value that the train will approach as it approaches its max speed (or 1000 inches/second if the "Use max speed for pitch shifting move sound" flag is not set).
Min move sound interval (MoveSoundMinTime) <float>
Minimum interval at which to play the move ping sound.
Max move sound interval (MoveSoundMaxTime) <float>
Maximum interval at which to play the move ping sound.
Manual Train Speed (manualspeedchanges) <boolean>
Train Speed is controlled through IO, handles accel, decel times.
Manual Accel Speed (manualaccelspeed) <float>
Units per second to accelerate to target speed.
Manual Decel Speed (manualdecelspeed) <float>
Units per second to decelerate to target speed.
Note.pngNote:The above three keyvalues are !FGD in Left 4 Dead and later, but appear to still exist in the engine.

Distance between wheels is the distance in Hammer Units between the front axle and rear axle of your train. The rear axle moves the train and stays on the track. The front axle turns as it approaches path_tracks and does not stay on the track.

Flags

No Pitch (X-rot) : [1]
No User Control : [2]
Forward Only : [4] !FGD
Controlling player may only move the entity forward, or stop it.
Passable : [8]
Disables collisions on the object.
Always Fixed Orientation : [16]
Rideable Train : [128]
Does not knock entities off or cause damage.
Use max speed for pitch shifting move sound : [256]
Not blockable by players : [512]

Inputs

SetSpeed <floatRedirectInput/float>
Set the speed of the train, as a ratio of max speed [0, 1]
SetSpeedDir <floatRedirectInput/float>
Set the speed of the train, as a ratio of max speed. Negative values reverse the direction [-1, 1]
SetSpeedReal <floatRedirectInput/float>
Set the speed of the train. Must be a positive value from 0 to max speed.
SetSpeedDirAccel <floatRedirectInput/float> (not in Left 4 Dead)
Accel/Decel to the specified speed, as a ratio of max speed. Negative values reverse the direction [-1, 1]
SetSpeedForwardModifier <floatRedirectInput/float> (removed since Left 4 Dead)
Applies the given modifier to all forward speeds. [0, 1]
TeleportToPathTrack <targetnameRedirectInput/string> (removed since Left 4 Dead)
Teleport the train to the designated path track. This can be in a new path.
Note.pngNote:The above three inputs appear to have been added to Source 2007 games post-release for TF2's Payload mode, but did not make it into later games, resulting in their apparent "removal". However, SetSpeedDirAccel did later get ported in Left 4 Dead 2 Left 4 Dead 2.
MoveToPathNode <targetnameRedirectInput/string> (in all games since Portal 2)
Move the train to a specific path_track, stopping when it gets there. Must be in the same path.
TeleportToPathNode <targetnameRedirectInput/string> (in all games since Portal 2)
Teleport to another path_track and stop the train. This can be in a new path.
LockOrientation  (in all games since Portal 2)
Lock the current orientation of the train.
UnlockOrientation  (in all games since Portal 2)
Unlock the current orientation of the train.
SetMaxSpeed <floatRedirectInput/float> (in all games since Portal 2)
Set a new max speed for the train.
Stop
Stop the train.
StartForward
Start the train moving forward.
StartBackward
Start the train moving backward.
Icon-Bug.pngBug:If the train's corresponding path_tracks do not have "New Train Speed" set to a nonzero number, StartBackward will exhibit undesired behavior including the train freezing or moving in the wrong direction. This bug can be a pain if the train needs to ride through the path_track again at a different speed. This can be fixed by firing an "addOutput speed '#'" input at the path_track in question.  [todo tested in ?]
Resume
Resume the train moving in the current direction after it was stopped via the Stop or Toggle input.
Reverse
Reverse the direction of the train.
Toggle
Toggle the train between start and stop.

Outputs

OnStart
Fired when the train starts moving in either direction.
OnNextPoint  !FGD
Fires continuously every tick when the train is currently moving to its next destination.
Warning.pngWarning:In the default FGD, this is incorrectly listed as "OnNext" and has an incorrect description ("Fires when this train picks a new point to move towards (and just after OnStart)")
OnArrivedAtDestinationNode  (in all games since Portal 2)
Fired when this train arrives at a destination that was specified by the MoveToPathNode input.

See also