Triggers

Triggers are an essential tool for enabling interactions between objects in 3D space. By setting up trigger events, you can activate desired functionality when two or more objects come into contact with each other.

For example, you can create an event to occur when a 3D model enters a designated zone or when two objects collide with each other.

Using Triggers to change a Node's State

Adding Triggers

To add a trigger to your project, simply right-click on the Hierarchy and go to the Triggers dropdown. Currently, Mattercraft supports four trigger shapes:

  • SphereTrigger
  • PointTrigger
  • PlaneTrigger
  • CubeTrigger

Adding a Trigger

Each of these shapes defines the area in which the trigger event will occur.

Using Triggers

Tags

For triggers to interact with each other, they must have the exact same tag assigned to each of them. Tags act as identifiers, meaning that triggers with the same tag will interact with each other while ignoring others with different tags, or those with none assigned at all.

Node Tags property

To set the tag for a trigger, you should:

  1. Navigate to the Properties Panel and find the Other section (near the bottom)
  2. Add the exact same tag name (using any naming convention) to the Tag property for all triggers that should interact with each other.

    Local tags

By default, triggers are set up to fire globally. If you want your trigger to only interact with components in its current zcomp, then you can add a local: tag. For example local:myTriggerTag. All subsequent tags should then take this same naming convention.

Is Trigger

Triggers can only emit events when they intersect with another trigger that is marked as a Trigger.

Is Trigger property

Only one trigger in the interaction needs to be marked as a trigger, typically the one for which you've set up the events.

Trigger events

Triggers emit the following events:

Event Description
onTriggerEnter Fired when the triggers first intersect.
onTriggerMove Fires when the triggers are intersecting and moving.
onTriggerLeave Fired when as soon as a trigger leaves another.

Triggering events with Behavior Actions

You may trigger events from within the Mattercraft visual editor, or with custom scripts.

You can activate a state by using the following instructions:

  1. Find the Trigger you wish to trigger events with inside the Hierarchy Panel and select it
  2. Head to the Behavior Actions Panel and click on the + (plus) icon
  3. Assign the desired Behavior Action and the trigger’s Event property

Node Event property

Triggering events with a Script

You can also listen for trigger events in a script. Below is an example of activating a state with the onTriggerEnter event handler:

// Register that the trigger node should be listening
//  to an event,  in this case onTriggerEnter.
this.register(this.instance.onTriggerEnter, evt  => {

     // Activate the state by finding the layer containing the
     // state clip, and then the state itself
     this.zcomponent.animation.layers.myLayer.clips.myState.play();

});
zapcode branded_zapcode i