Skip to main content

Triggers

Colliders can be set as triggers, this allows them to detect collisions without being affected by them.

This example shows a box collider that is set as a trigger and a falling box.

When the falling box collides with the trigger, a message will be logged to the console.

this.world!.config.collisionClasses.push({ name: 'Trigger' });

{ mass: 0, isTrigger: true },
createBoxCollider(1, 1, 1, 'Trigger'),
);

this.events.addListener(
TEventTypesPhysics.COLLISION_START,
'Trigger',
(event: TCollisionStartEvent) => {
if (event.payload.entityA === box) {
console.log('Collision started', event);
}
},
);