Triggers
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
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: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.
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
- Brush entity
- Inputs and Outputs
- Filters
- Special:PrefixIndex/trigger
- showtriggers_toggle, a console command to make trigger brushes visible
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)
andAddSolidFlags(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().