Triggers: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Created page with 'http://developer.valvesoftware.com/wiki/Trigger')
 
No edit summary
 
(13 intermediate revisions by 8 users not shown)
Line 1: Line 1:
http://developer.valvesoftware.com/wiki/Trigger
{{LanguageBar}}[[Category:Glossary]][[Category:Level Design]][[Category:Programming]]
'''Triggers''' are [[entity|entities]] which respond to the presence of other entities. Trigger [[brush|brushes]] and trigger [[Mesh#Source_2|meshes]] can be created by mappers, while programmers can make anything into a trigger.{{Note|Having the <tt>Angles</tt> keyvalue in a trigger can actually rotate it in the game. This could be useful, but also annoying if it is left over and not removed.}}
 
== Level Design ==
[[File:Toolstrigger.gif|right|tools/toolstrigger]]
 
There are many types of [[brush entity]] trigger that can be created from within Hammer; see [[Special:PrefixIndex/trigger]] for the complete list. The most common general-purpose ones are {{ent|trigger_once}}, {{ent|trigger_multiple}}, {{ent|trigger_look}}, and {{ent|trigger_proximity}}. They all share these properties and outputs:
; {{ent|Tool textures|alt=tools/toolstrigger}}: All trigger entities must use this material on all faces. Alternatively, a custom trigger material can be made using {{ent|%CompileTrigger}}.
: {{note|Triggers can be textured with materials without %CompileTrigger (triggers are always nonsolid and invisible), but using %CompileTrigger ensures that it will not waste lightmap usage.}}
; Filters: [[Filters|Filter entities]] can be used to restrict what activates the trigger.
; Filter Flags: There are a series of [[Hammer Object Properties Dialog#Flags Tab|flags]] that permit simple filtering without the need of a second entity.
; <code>OnStartTouch</code>
; <code>OnEndTouch</code>
: Outputs called whenever a entity matching all filters enters/leaves the trigger, regardless of whether it has passed any further tests. The entity that entered or left is the {{ent|Targetname#Keywords|alt=!caller}}.
; <code>OnStartTouchAll</code>
; <code>OnEndTouchAll</code>
: As above, but only called if there are no other (filtered) entities touching the trigger.
; <code>OnTouching</code>
; <code>OnNotTouching</code>
: One of these outputs will be fired in response to the <code>TouchTest</code> input. All triggers support this, but most do not have it listed in their [[FGD]].
; <code>OnTrigger</code>: Fires whenever an entity matches all of the trigger's criteria.
{{warning|For a {{ent|trigger_once}}, this output is '''''not''''' the same as <code>OnStartTouch</code> and <tt>OnStartTouchAll</tt>. When a trigger that does not reset is activated, it removes itself from the map after 0.1 seconds. <code>OnStartTouch</code> can still be re-triggered during that 0.1 second window.}}
 
=== See also ===
* [[Brush entity]]
* [[Mesh entity]]
* [[Inputs and Outputs]]
* [[Filters]]
* [[Special:PrefixIndex/trigger]]
* {{cmd|showtriggers_toggle}}, a console command to make trigger brushes visible
 
== Programming ==
All entities can respond to collisions with other entities (see {{ent|Touch()}}). If you want touches without actual collisions, then you have two options:
; <code>SetSolid(SOLID_NONE)</code> <span style="font-weight:normal;">and</span> <code>AddSolidFlags(FSOLID_TRIGGER)</code>
: This will cause the entity to receive touches as things pass through it.
; <code>CollisionProp()->UseTriggerBounds(true,iBloatSize)</code>
: This will give the entity a "trigger box" that extends around its [[bounding box]] by iBloatSize units in X/Y and (iBloatSize/2) in +Z (-Z remains the same). The trigger box is world aligned and will work regardless of the object's solidity and collision group. It will be visible as a light blue box when the <code>ent_bbox</code> console command is used.
: Valve uses trigger boxes for all pickup items. Their bloat size is 24, a surprisingly large figure.
 
=== Brush ===
To make a new brush trigger, which tests using the shape of its brush model instead of a bounding box, inherit from <tt>CBaseTrigger</tt> and call <tt>InitTrigger()</tt>.

Latest revision as of 22:12, 13 June 2025

English (en)Русский (ru)中文 (zh)Translate (Translate)

Triggers are entities which respond to the presence of other entities. Trigger brushes and trigger meshes can be created by mappers, while programmers can make anything into a trigger.

Note.pngNote:Having the Angles keyvalue in a trigger can actually rotate it in the game. This could be useful, but also annoying if it is left over and not removed.

Level Design

tools/toolstrigger

There are many types of brush entity trigger that can be created from within Hammer; see Special:PrefixIndex/trigger for the complete list. The most common general-purpose ones are trigger_once, trigger_multiple, trigger_look, and trigger_proximity. They all share these properties and outputs:

tools/toolstrigger
All trigger entities must use this material on all faces. Alternatively, a custom trigger material can be made using %CompileTrigger.
Note.pngNote:Triggers can be textured with materials without %CompileTrigger (triggers are always nonsolid and invisible), but using %CompileTrigger ensures that it will not waste lightmap usage.
Filters
Filter entities can be used to restrict what activates the trigger.
Filter Flags
There are a series of flags that permit simple filtering without the need of a second entity.
OnStartTouch
OnEndTouch
Outputs called whenever a entity matching all filters enters/leaves the trigger, regardless of whether it has passed any further tests. The entity that entered or left is the !caller.
OnStartTouchAll
OnEndTouchAll
As above, but only called if there are no other (filtered) entities touching the trigger.
OnTouching
OnNotTouching
One of these outputs will be fired in response to the TouchTest input. All triggers support this, but most do not have it listed in their FGD.
OnTrigger
Fires whenever an entity matches all of the trigger's criteria.
Warning.pngWarning:For a trigger_once, this output is not the same as OnStartTouch and OnStartTouchAll. When a trigger that does not reset is activated, it removes itself from the map after 0.1 seconds. OnStartTouch can still be re-triggered during that 0.1 second window.

See also

Programming

All entities can respond to collisions with other entities (see Touch()). If you want touches without actual collisions, then you have two options:

SetSolid(SOLID_NONE) and AddSolidFlags(FSOLID_TRIGGER)
This will cause the entity to receive touches as things pass through it.
CollisionProp()->UseTriggerBounds(true,iBloatSize)
This will give the entity a "trigger box" that extends around its bounding box by iBloatSize units in X/Y and (iBloatSize/2) in +Z (-Z remains the same). The trigger box is world aligned and will work regardless of the object's solidity and collision group. It will be visible as a light blue box when the ent_bbox console command is used.
Valve uses trigger boxes for all pickup items. Their bloat size is 24, a surprisingly large figure.

Brush

To make a new brush trigger, which tests using the shape of its brush model instead of a bounding box, inherit from CBaseTrigger and call InitTrigger().