All shapes that can be created in PhysX can be flagged as a trigger shape. A trigger shape doesn't participate in the simulation, but can be configured to participate in scene queries. Its shape doesn't involve any physical collision. A trigger shape is mainly used to detect if any rigid body overlapped its spatial volume or not. If yes, it triggers a callback function. This feature is frequently used in games. For example, let's say you are making a sci-fi game in which whenever a player comes in front of any door, it is automatically opened for the player. To do this, simply place an actor with a cube shape in front of the door and flag it as triggerShape
. Then write a game logic that plays the door opening animation whenever the cube actor detects an overlap between the player's shape and its own shape.
The code snippet to flag the shape of an actor as a trigger is as follows:
//Setting trigger flag true for 'triggerShape' PxShape* triggerShape; triggerActor->getShapes...