Working With Trigger Volume
Last updated
Last updated
A trigger volume is an invisible, non-collidable area that generates a Trigger event whenever an object or avatar enters or exits the area. This can be useful for opening automatic doors, counting visitors, and many other applications.
Here are some steps to set up a trigger volume. For the purpose of this guide, we will be using the example script triggerannounce.cs, which announces when something enters or exits the trigger volume.
Create a new experience as described in Quick start: Creating experiences in Sansar. For simplicity, choose the Base Template scene as the experience's starting template.
Remember that trigger volumes are invisible. You may want to consider using visible objects to identify the trigger location or not, depending on your desired outcome.
In this example, place two or more visible objects in such a way that you can easily navigate between them. We have used the free Sansar Example Crate 1.0 from the Sansar Store. This step is to make sure we can find the trigger volume while visiting the scene.
From the System Objects tab of your Inventory, drag a new Trigger Volume into the scene.
In this example, position it between the visible objects you have placed, such that a visitor must pass through the trigger volume in order to walk between the visible objects.
Choose a script that makes use of the Trigger event.
For the purposes of this example, upload the triggerannounce.cs script.
Drag the script onto the trigger volume, or add a script component on the trigger volume container.
Save, then Build your scene.
When the scene has finished building, click the Visit Now button that appears to visit your scene.
When visiting the scene, walk into the trigger volume to trigger the attached script. Remember that trigger volumes are invisible to visitors, so you should walk towards the visible object markers, if there is one.
In the exercise above, the example script, triggerannounce.cs, is added to the trigger volume in between two (visible) objects. Walk into the area indicated by the visible objects you placed earlier to trigger the script. When you enter or exit the trigger volume, example script causes the trigger volume to log your entry or exit in chat.
Note**:** In order to view chat messages from any script, you must have the Chat app open.
To access the trigger volume's properties, find the trigger volume's name in the Scene Objects panel, right-click it, and choose Properties to open its Properties panel.
The trigger volume properties include:
Position - The location of the trigger volume's center.
Rotation - The trigger volume's orientation in the scene.
Scale - Increases or decreases the size of the entire trigger volume; defaults to 1.0.
Movable From Script - Set to On to allow scripts to move, rotate, and scale the trigger volume.
Collides With - Determines what kinds of objects can activate the trigger volume. For the best performance, Avatars and Dynamic Bodies is selected by default, but you can allow additional object types by selecting Everything from the dropdown. For additional information about the types of movable objects, including dynamic objects, see Object motion types.
Extents / Radius - May show one or the other based on the VolumeType selected. Changing the VolumeType defines the shape of the trigger volume. See changing the volume type below for information on Extents and Radius and how to change the VolumeType between a Box or a Sphere.
You can change a trigger volumes shape by accessing the volume component within the trigger volume's container. To access this:
Find the trigger volume's name in the Scene Objects panel and click on the blue arrow beside the name to drop down the trigger volume's list of components.
Find the Volume component and right-click it to open a sub-menu of actions.
Then, choose Properties from the sub-menu to open the volume Properties panel.
The properties in the volume-specific properties panel include:
VolumeType - The volume properties panel allows you to set the shape of the trigger volume to either a Box or Sphere by using the drop down. Box is the default volume type. Keep in mind that this can only be set in the Volume properties panel.
Note: Mesh is currently a selectable VolumeType on the drop down list. However, it is currently not supported with trigger volumes.
Depending on whether you've chosen to use Box or Sphere as the VolumeType, you will see the following show up on the volume properties panel and the trigger volume's main properties panel:
Extents - For the Box VolumeType only; defines the proportions of the trigger volume in the X, Y, and Z coordinates.
Radius - For the Sphere VolumeType; defines the radius of a spherical trigger volume.
Note: While HasCollision appears on the volume properties panel, it is currently not supported with trigger volumes.