This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
UnigineEditor
界面概述
资产工作流程
设置和首选项
项目开发
调整节点参数
Setting Up Materials
Setting Up Properties
照明
Landscape Tool
Sandworm
使用编辑器工具执行特定任务
Extending Editor Functionality
嵌入式节点类型
Nodes
Objects
Decals
Light Sources
Geodetics
World Objects
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Physical Trigger

A physical trigger is an object firing callbacks when physical objects get inside or outside of it. There are 4 types of the 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.

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 C++, C# or UnigineScript API. The shape of such object can 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:
    1. trigger_00
    2. trigger_01
    3. trigger_02
  • The fragment from the video tutorial on physics demonstrating the physical trigger

Adding Physical Trigger#

To add a physical trigger to the scene via UnigineEditor:

  1. Run the project with UnigineEditor.
  2. On the Menu bar, click Create -> Logic -> Physical Trigger.

  3. 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 fire callbacks when the object enters or leaves it.
Collision Mask
  • In case of the physical object, the collision mask of the physical trigger must match the collision mask of the physical object's shape.
  • In case of the non-physical collider object, the collision mask of the physical trigger must match the collision mask of the object's surface.
Type Type of the physical trigger: sphere, capsule, cylinder, or box.
Size Size of the physical trigger, namely:
  • Radius, in case of a sphere
  • Radius and height, in case of a capsule or a cylinder
  • Dimensions, in case of a box

Setting Up Callbacks#

To add an enter or leave callback, write a callback function that receives a Body as its first argument. Then use an addEnterCallback or addLeaveCallback method to specify the function to be called.

Source code (C++)
// add the enter callback to be fired when a body enters the physical trigger
physicalTrigger->addEnterCallback(MakeCallback(this, &AppWorldLogic::enter_callback));
// add the leave callback to be fired when a body leaves the physical trigger
physicalTrigger->addLeaveCallback(MakeCallback(this, &AppWorldLogic::leave_callback));
Source code (C#)
// add the enter callback to be fired when a body enters the physical trigger
physicalTrigger.addEnterCallback(enter_callback);
// add the leave callback to be fired when a body leaves the physical trigger
physicalTrigger.addLeaveCallback(leave_callback);
Last update: 2021-04-09
Build: ()