Triggers#

Trigger Volumes can be applied to a prim’s collision mesh and can be used to detect when another prim enters or leaves the trigger’s space.

Trigger Volumes#

Crate a Trigger#

Triggers are created by assigning a trigger Schema to a prim.

Note

The prim must have a collision mesh for the trigger to work

Setup the trigger using the PhysxTriggerAPI USD schema.

from pxr import PhysicsSchemaTools, PhysxSchema, UsdPhysics

# optional, just in case the prim doesn't have a collision attribute already assigned
UsdPhysics.CollisionAPI.Apply(trigger_prim)
PhysxSchema.PhysxTriggerAPI.Apply(trigger_prim)
self.triggerStateAPI = PhysxSchema.PhysxTriggerStateAPI.Apply(trigger_prim)

Detect a Collision#

Trigger Volumes don’t use python event callbacks, so instead we poll the trigger state per frame.

Note

Triggers can execute scripts on trigger “events”, see the Physics Demo Scene : Triggers for details

from pxr import PhysicsSchemaTools, PhysxSchema, UsdPhysics

def physics_update(self, e: carb.events.IEvent):

    triggerColliders = self.triggerStateAPI.GetTriggeredCollisionsRel().GetTargets()
    if len(triggerColliders) > 0:
        for collision in triggerColliders:
            print(f"Prim path: {collision} : is touching our Trigger")