从Unity迁移到UNIGINE:物理
While Unity software provides two physics engines: Physics and Physics2D, UNIGINE's built-in Physics module works only in 3 dimensions.Unity软件提供了两个物理引擎:UNIGINE的内置引擎Physics和Physics2D物理该模块仅在3维上起作用。
In UNIGINE, physics simulation can be enabled both when you enter Play mode and right in the editor. Click the Physics toggle in the top toolbar (if the button is greyed out, toggle Animation on via the button next to it):在UNIGINE中,既可以在进入Play模式时又可以在编辑器中启用物理模拟。单击顶部工具栏中的Physics开关(如果该按钮为灰色,则通过其旁边的按钮将Animation打开):
To disable simulation and reset the state of all physics-driven objects, uncheck the toggle and the world will return to its previously saved state.要禁用模拟并重置所有物理驱动对象的状态,请取消选中切换开关,世界将返回其先前保存的状态。
Rigid Bodies刚体#
The Unity Rigidbody component is responsible for physical behaviour for GameObject.Unity Rigidbody组件负责GameObject的物理行为。
In UNIGINE, some Object types are capable of being physics-driven. In the Physics tab of the Parameters window you can assign a Physical Body to an object, which can be considered physical approximations of real-life objects. One of them is Rigid Body simulating the most commonly used rigid body dynamics.在UNIGINE中,某些对象类型可以由物理驱动。在Parameters窗口的Physics标签中,您可以分配一个身体物体,可以认为是现实生活中物体的物理近似。其中之一是Rigid Body,它模拟最常用的刚体动力学。
Global Physics settings, such as the global gravity vector and quality, are available in the Settings window compared to the Unity Physics section of the Project Settings:全局物理设置与“项目设置”的Unity Physics部分相比,Settings窗口中提供了诸如全局重力矢量和质量之类的信息:
Colliders / Shapes碰撞器/形状#
Collision Shapes in UNIGINE play the part of Unity Collider components, shapes are configured in the Shapes section. Here's the list of shape types compared to the Collider components:碰撞形状在UNIGINE中扮演Unity Collider组件的一部分,在Shapes部分中配置形状。以下是与Collider组件相比的形状类型列表:
Unity software | UNIGINE |
---|---|
Box Collider | Box |
Sphere Collider | Sphere |
Capsule Collider | Capsule |
— | Cylinder |
Mesh Collider | Convex |
Wheel Collider | implemented as the Wheel Joint实现为Wheel Joint |
Terrain Collider | not provided, collisions are handled by the Terrain object itself未提供,则冲突由Terrain对象本身处理 |
The same way as you create Compound Collider in Unity Editor, you can combine several shapes to define a more complex collision shape in UNIGINE:与在Unity编辑器中创建Compound Collider相同,可以组合多个形状以在UNIGINE中定义更复杂的碰撞形状:
Colliders are also often used as triggers in Unity scripting.对撞机也经常用作触发因素在Unity脚本中。
Static Collider静态对撞机#
In Unity software, you would create GameObject that has Collider but no RigidBody to create a non-moving collider.在Unity软件中,您将创建具有Collider但没有RigidBody的GameObject来创建不可移动的对撞机。
UNIGINE features two types of collisions, you can apply any option to make an object to be static collider:UNIGINE具有两个碰撞类型,您可以应用任何选项使对象成为静态对撞机:
-
Shape-Shape collision: between two objects with physical properties assigned (i.e. between their shapes).形状-形状碰撞:在两个分配了物理属性的对象之间(即,在它们的形状之间)。
To create a static collider perform the following:要创建静态对撞机,请执行以下操作:
- Assign Dummy Body to the node.将Dummy Body分配给该节点。
- Add collision shapes.添加碰撞形状。
-
Shape-Surface collision: between an object with physical properties assigned and a non-physical object (i.e. between a shape and a mesh surface).Shape-Surface碰撞:已分配了物理属性的对象与非物理对象之间(即,形状与网格表面之间)。
To make a mesh surface (e.g. of an ObjectMeshStatic) provide static collisions, just enable the Collision flag for it:要使网格表面(例如ObjectMeshStatic的表面)提供静态碰撞,只需为其启用Collision标志:
Thus, you can really quickly enable collisions with the scene geometry, however, this method may be more performance consuming than the other one, especially if the world contains a large number of polygons.因此,您确实可以快速启用与场景几何体的碰撞,但是,这种方法可能比另一种方法消耗更多的性能,尤其是在世界包含大量多边形的情况下。
Dynamic (Rigidbody) Collider动态(刚体)对撞机#
In terms of Unity software, this is GameObject with Collider and a normal Ridigbody attached. Rigidbody collider is fully physics-driven and subject to collision and forces applied to it (either by other objects or from script).就Unity软件而言,这是GameObject,其中包含Collider和一个正常的Ridigbody。 Rigidbody对撞机是完全由物理驱动的,并且会受到碰撞和施加在其上的力(通过其他对象或脚本产生的力)。
To create such a collider object in UNIGINE, you assign Rigid Body to it and create the required set of Shapes to define its collision geometry.要在UNIGINE中创建这样的对撞机对象,您可以为其分配Rigid Body并创建所需的形状定义其碰撞几何。
Kinematic Collider运动对撞机#
Kinematic Collider is the term for an object that is logic-driven but affects other physically based objects in the scene (for example, a character or a door). In Unity software, such objects are created by enabling the IsKinematic property of the Rigidbody component.Kinematic Collider是逻辑驱动的对象的术语,但会影响场景中其他基于物理的对象(例如,角色或门)。在Unity软件中,通过启用Rigidbody组件的IsKinematic属性来创建此类对象。
In UNIGINE you should use an object surface with the Collision flag enabled to provide Shape-Surface collisions. When being moved (e.g. from code), such an object acts as a kinematic collider and influences physics-driven objects.在UNIGINE中,应使用启用了Collision标志的对象表面来提供Shape-Surface碰撞。在移动时(例如,从代码中移出),此类对象将充当运动对撞机并影响物理驱动的对象。
Layer-Based Collision Detection基于层的冲突检测#
In Unity Editor, layer-based collision detection is defined by configuring the Collision Matrix in the Physics category of the Project Settings:在Unity编辑器中,通过在“项目设置”的Physics类别中配置“碰撞矩阵”来定义基于层的碰撞检测:
In UNIGINE, selective collision detection is controlled via Collision mask of both shapes and surfaces depending on the type of collision detection used:在UNIGINE中,根据形状和表面的Collision遮罩来控制选择性碰撞检测,具体取决于碰撞检测的类型用过的:
Shape Collision Mask |
Surface Collision Mask |
Two objects will collide only if their Collision masks match (one bit at least).仅当两个对象的Collision掩码匹配(至少一位)时,它们才会发生碰撞。
For more details proceed to the dedicated article:有关更多详细信息,请继续阅读专用文章:
Joints关节#
As well as Unity software, UNIGINE provides support for Joints to connect physically-driven objects and restrict their movement relative to each other. Here is a list of Unity Joint components compared to the joint types available in UNIGINE:除Unity软件外,UNIGINE还支持关节连接物理驱动的对象并限制它们之间的相对运动。与UNIGINE中可用的关节类型相比,这是Unity Joint组件的列表:
Unity software | UNIGINE |
---|---|
Character Joint | Ball Joint |
Configurable Joint | — |
Fixed Joint | Fixed Joint |
Hinge Joint | Hinge Joint |
Spring Joint | Prismatic Joint, Cylindrical Joint |
implemented as Wheel Collider实现为Wheel Collider | Wheel Joint, Suspension Joint |
— | Path Joint |
implemented as Cloth Constraints in the Cloth component在Cloth组件中实现为Cloth Constraints | Particles Joint |
Ragdoll布娃娃#
Unity Editor has a simple wizard that lets you create a ragdoll by automatically generating all Colliders, Rigidbodies and Joints.Unity编辑器有一个简单的向导,可让您通过自动生成所有Colliders, Rigidbodies和Joints来创建布娃娃。
In UNIGINE, Ragdoll is a special type of body used to simulate ragdoll dynamics. It operates on rigid bodies, shapes and joints to simulate limbs of an arbitrary skinned model. Ragdoll creation is available only for Skinned Mesh.在UNIGINE中,Ragdoll是一种特殊的主体,用于模拟布娃娃动力学。它可以在刚体,形状和关节上运行,以模拟任意蒙皮模型的四肢。 Ragdoll创建仅适用于Skinned Mesh。
To switch between a bone-based animation and ragdoll simulation, use the Frame-based animation feature.要在基于骨骼的动画和布娃娃模拟之间切换,请使用Frame-based animation功能。
Physic Materials物理材料#
Unity Physic Materials contain a set of physical parameters used to adjust friction and bouncing effects of colliding objects.Unity Physic Materials包含一组物理参数,用于调整碰撞对象的摩擦和弹跳效果。
In UNIGINE, the Friction and Restitution parameters are available for shapes and surfaces and taken into account depending on the type of collision detection used:在UNIGINE中,Friction和Restitution参数可用于形状和表面并根据碰撞检测的类型用过的:
Shape Collision Mask |
Surface Collision Mask |
Character Controller角色控制器#
In Unity software, Character Controller is mainly used for simplified simulation of a third-person or a first-person player dynamics without making use of Rigidbody physics. A Capsule Collider is used in collisions.在Unity软件中,Character Controller主要用于简化第三人称或第一人称玩家动态的模拟,而无需使用刚体物理。 Capsule Collider用于冲突中。
UNIGINE provides collision detection for players as well. You can enable the Collision flag for Spectator, Persecutor and Actor players, the latter is a counterpart of Unity Character Controller, its shape is also approximated by a capsule collider. With collisions enabled a player acts like both dynamic and kinematic object: it is controlled from script, affects dynamic colliders and can be blocked by static colliders at the same time.UNIGINE为以下产品提供碰撞检测玩家们也一样您可以为Spectator, Persecutor和Actor播放器启用Collision标志,后者是Unity Character Controller的对应物,其形状也由胶囊对撞机近似。启用碰撞后,玩家的行为既类似于动态对象,也包括运动对象:它受脚本控制,影响动态对撞机,并且可以同时被静态对撞机阻止。
Constant Force恒力#
Unity Constant Force component is a quick utility providing a force constantly applied to a GameObject. It contains force and torque vector in relative and world coordinates.Unity Constant Force组件是一种快速实用程序,可提供不断施加到GameObject的力。它包含相对坐标和世界坐标中的力和转矩矢量。
In UNIGINE, you can use Physicals. These are objects inside of which there is an invisible force field affecting physics-driven objects. The Physical Wind is capable of applying a constant directed force to an object.在UNIGINE中,您可以使用Physicals。这些是其中存在不可见力场的物体,这些力场会影响物理驱动的物体。这 Physical Wind能够对物体施加恒定的定向力。