Triggers: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(Redirected page to Trigger)
No edit summary
Line 1: Line 1:
#redirect [[Trigger]]
'''Triggers''' are [[entity|entities]] which respond to the presence of other entities. Trigger brushes can be created by mappers, while programmers can make anything into a trigger.
 
== 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 '''[[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.
; 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 [[Targetname#Keywords|!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. For a trigger_once, this output is the same as <code>OnStartTouch</code> and <code>OnStartTouchAll</code>.
 
=== See also ===
 
* [[Brush entity]]
* [[Inputs and Outputs]]
* [[Filters]]
* [[Special:PrefixIndex/trigger]]
* <code>showtriggers_toggle</code>, a console command to make trigger brushes visible
 
== Programming ==
 
All entities can respond to collisions with other entities (see <code>[[Touch()]]</code>). 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 use 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 <code>[[CBaseTrigger]]</code> and call <code>InitTrigger()</code>.
 
[[Category:Level Design]]
[[Category:Programming]]
[[Category:Glossary]]

Revision as of 13:24, 3 April 2011

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

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.
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. For a trigger_once, this output is the same as OnStartTouch and OnStartTouchAll.

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 use 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().