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:Physical Trigger是当物理对象进入内部或外部时触发回调的对象。根据其形状,有四种类型的物理触发器:
- 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).要被触发器检测到,物理对象必须同时具有身体(具有与触发器的Physical掩码匹配的Physical掩码)和一个形状(具有与触发器的Collision掩码匹配的Collision掩码)。
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.也可以为Physical Trigger指定Exclusion掩码,用于防止检测形状冲突。此掩码独立于Collision掩码。
- For a body with a shape, the Exclusion mask can be set on the Physics tab of the Parameters panel.对于具有形状的物体,可以在Parameters面板的Physics选项卡上设置Exclusion蒙版。
- For the Physical Trigger, the mask can be set via C++, C# or UnigineScript API.对于Physical Trigger,可以通过以下方式设置掩码C ++,C#或UnigineScript API 。
To avoid collision detection between a shape and a Physical Trigger, the following conditions must be met:为了避免检测形状与Physical Trigger之间的碰撞,必须满足以下条件:
- The Collision mask set for the shape must match the Collision mask of the Physical Trigger.为形状设置的Collision遮罩必须比赛Physical Trigger的Collision掩码。
- The Exclusion mask set for the shape must match the Exclusion mask of the Physical Trigger.为形状设置的Exclusion遮罩必须比赛Physical Trigger的Exclusion掩码。
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.可以通过API获取参与Physical Trigger接触的物理对象。还可以获得这种对象扫描的形状。此外,您可以获得对象穿透的深度,接触点的坐标及其法线。
See also也可以看看#
- The PhysicalTrigger class to manage Physical Trigger nodes via APIPhysicalTrigger类,用于通过API管理Physical Trigger节点
A set of samples located in the data/samples/physicals folder:位于data/samples/physicals文件夹中的一组样本:
- trigger_00
- trigger_01
- trigger_02
- The fragment from the video tutorial on physics demonstrating the Physical Trigger来自的片段演示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:通过UnigineEditor将Physical Trigger添加到场景中:
- Run the project with UnigineEditor.跑步UnigineEditor的项目。
-
On the Menu bar, click Create -> Logic -> Physical Trigger.在菜单栏上,单击Create -> Logic -> Physical Trigger。
-
Click somewhere in the world to place the Physical Trigger.单击世界上的某个地方以放置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.新的Physical Trigger节点将被添加到UnigineEditor,您将能够通过Parameters窗口对其进行编辑。默认情况下,将创建半径为1的球体触发器。
Editing Physical Trigger编辑物理触发器#
In the Physical Trigger section (Parameters window -> Node tab), you can adjust the following parameters of the physical trigger:在Physical Trigger部分(Parameters窗口→Node选项卡)中,可以调整物理触发器的以下参数:
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.切换Physical Trigger节点的编辑模式。启用后,节点的大小或半径(取决于其大小)类型)可以更改:每侧/轴都用彩色的矩形/圆形突出显示。要更改大小/半径,请拖动相应的矩形/圆形。 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.Physical Trigger的Physical掩码必须比赛物理对象的Physical掩码。否则,当对象进入或离开对象时,Physical Trigger不会触发回调。 |
Collision Mask |
|
Type | Type of the Physical Trigger: sphere, capsule, cylinder, or box.Physical Trigger的类型:sphere, capsule, cylinder或box。 |
Size |
Size of the Physical Trigger, namely:Physical Trigger的大小,即:
|
Handling Events事件处理#
要添加回车或离开回调,请编写一个回调函数,该函数将Body作为其第一个参数。然后使用getEventEnter()或getEventLeave()方法指定要调用的函数。
// 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);