Physical Trigger
The Physical Trigger is an object that triggers events when physical objects get inside or outside of it. There are 4 types of physical triggers based on their shape:
- Sphere trigger of the specified radius
- Capsule trigger of the specified radius and height
- Cylinder trigger of the specified radius and height
- Box trigger of the specified size along the axes
To be detected by the trigger, a physical object must have both a physical body (with the Physical mask that matches the Physical mask of the trigger) and a shape (with the Collision mask that matches the Collision mask of the trigger).
It is also possible to specify the Exclusion mask for the Physical Trigger that is used to prevent detecting collisions with shapes. This mask is independent of the Collision mask.
- For a body with a shape, the Exclusion mask can be set on the Physics tab of the Parameters panel.
- For the Physical Trigger, the mask can be set via C++, C# or UnigineScript API.
To avoid collision detection between a shape and a Physical Trigger, the following conditions must be met:
- The Collision mask set for the shape must match the Collision mask of the Physical Trigger.
- The Exclusion mask set for the shape must match the Exclusion mask of the Physical Trigger.
Physical objects participating in the contact with the Physical Trigger can be obtained via API. The shape of such object scan also be obtained. Moreover, you can get the depth of the object penetration, coordinates of the contact point, and its normal.
See also#
- The PhysicalTrigger class to manage Physical Trigger nodes via API
A set of samples located in the data/samples/physicals folder:
- trigger_00
- trigger_01
- trigger_02
- The fragment from the video tutorial on physics demonstrating the Physical Trigger
- Videotutorial on How To Use Physical Triggers to Catch Physical Objects
Adding Physical Trigger#
To add a Physical Trigger to the scene via UnigineEditor:
- Run the project with UnigineEditor.
-
On the Menu bar, click Create -> Logic -> Physical Trigger.
-
Click somewhere in the world to place the Physical Trigger.
A new Physical Trigger node will be added to UnigineEditor, and you will be able to edit it via the Parameters window. By default, the sphere trigger with 1-unit radius is created.
Editing Physical Trigger#
In the Physical Trigger section (Parameters window -> Node tab), you can adjust the following parameters of the physical trigger:
Edit Size |
Toggles the editing mode for the Physical Trigger node. When enabled, the size or the radius of the node (depending on its type) can be changed: each side/axis is highlighted with the colored rectangle/circle. To change the size/radius, drag the corresponding rectangle/circle. Editing of sphere-shaped physical trigger
|
---|---|
Physical Mask | The Physical mask of the Physical Trigger must match the Physical mask of the physical object. Otherwise, the Physical Trigger won't trigger events when the object enters or leaves it. |
Collision Mask | |
Type | Type of the Physical Trigger: sphere, capsule, cylinder, or box. |
Size |
Size of the Physical Trigger, namely:
|
Handling Events#
To perform specific actions when physical objects enter or leave the Trigger, you should create a handler function that receives a Body as its first argument and implements the desired actions. Then subscribe to the Enter and/or Leave events and call connect().
// subscribe to Enter event when a body enters the physical trigger with your handler
physicalTrigger->getEventEnter().connect(enter_event_handler);
// subscribe to Leave event when a body leaves the physical trigger with your handler
physicalTrigger->getEventLeave().connect(leave_event_handler);
// subscribe to Enter event when a body enters the physical trigger with your handler
physicalTrigger.EventEnter.Connect(enter_event_handler);
// subscribe to Leave event when a body leaves the physical trigger with your handler
physicalTrigger.EventLeave.Connect(leave_event_handler);