Skip to main content

Trigger Volumes

Trigger volumes are static collision shapes that can fire events whenever a rigid body enters or leaves the volume. This can be useful for determining when a goal is scored in a football game or when a race car reaches the finish line.

To create a trigger volume, add a Collision Component to an entity and configure its shape. Do not add a rigid body component to the trigger volume entity.

Trigger Volume

A simple script is needed to check if a rigid body based entity has entered or left the volume:

var TriggerVolume = pc.createScript('triggerVolume');

// initialize code called once per entity
TriggerVolume.prototype.initialize = function() {
this.entity.collision.on('triggerenter', function (entity) {
console.log(entity.name + ' has entered trigger volume.');
});
this.entity.collision.on('triggerleave', function (entity) {
console.log(entity.name + ' has left trigger volume.');
});
};