This tutorial was originally created by wisemx.
Illustrated in this project:
- Player can see a Monitor on the wall.
- When the player gets closer, within the trigger, and looks at the monitor it will cause a gunshot to be heard and the NPC Citizen in the camera will appear to have been shot.
This is done with a
trigger_look is an entity used to trigger an event when the player looks at something. It fires
OnTrigger when the player looks at the specified target entity for the set amount of time. The player needs to be inside of the trigger volume. When the player leaves the trigger or looks away from the target entity the clock resets. Additionally if the Use Velocity instead of facing flag is checked, it uses the player's velocity instead of the player's view, and determines when the player is moving toward the target entity. This is useful for triggering when the player is driving a vehicle towards something. These triggers are only designed for single-player HL2.
Shown below is the
trigger_look volume I created for this project.
Notice the trigger area in the image above. When the player is inside this trigger and looks at the monitor the events will fire. The player can look at the monitor from outside the trigger and nothing will happen. This trigger entity is like other trigger entities and can be flagged for Player, NPC or Filtered contact types.
Shown here are the properties for the
trigger_look used in this project.
- Start disabled: No
- Look Target: monitor_1
- Look Time: 0.5
- FieldOfView: 0.9
- Timeout: 0
- Flags: Fire once and Clients
|My Output||Target Entity||Target Input||Parameter||Delay||Only Once|
Notice the timing used in these outputs. The
ambient_generic is used to play the gunshot sound a fraction of a second before the NPC citizen dies, on camera.
Also notice that we could have added a pause in the properties for the
trigger_look by adding a non-zero value to the property Timeout. This would be handy in a case like steps leading up to a door that will spring open.