# Migrating to UNIGINE from Unity: Physics While *Unity* software provides two physics engines: *Physics* and *Physics2D*, UNIGINE's built-in [Physics](../../principles/physics/index.md) module works only in 3 dimensions. 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_physics_toggle.png) 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*. 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](../../principles/physics/bodies/index.md) to an object, which can be considered physical approximations of real-life objects. One of them is **[Rigid Body](../../principles/physics/bodies/rigid/index.md)** simulating the most commonly used *rigid body dynamics*. **[Global Physics settings](../../editor2/settings/physics_global/index.md)**, 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_unigine_physics.png) ## Colliders / Shapes **[Collision Shapes](../../principles/physics/shapes/index.md)** 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: | *Unity* software | UNIGINE | |---|---| | Box Collider | [Box](../../principles/physics/shapes/index.md#box) | | Sphere Collider | [Sphere](../../principles/physics/shapes/index.md#sphere) | | Capsule Collider | [Capsule](../../principles/physics/shapes/index.md#capsule) | | � | [Cylinder](../../principles/physics/shapes/index.md#cylinder) | | Mesh Collider | [Convex](../../principles/physics/shapes/index.md#convex) | | Wheel Collider | implemented as the *[Wheel Joint](../../principles/physics/joints/index.md#wheel)* | | Terrain Collider | not provided, collisions are handled by the *[Terrain](../../objects/objects/terrain/landscape_terrain/landscape_layer_map.md#landscape_asset_parameters)* object itself | > **Notice:** A Convex shape is generated automatically based on the object geometry, you don't need to specify a collision mesh explicitly. Also, it is possible to generate a set of convex hulls to define a more complex concave mesh by using the *[Autogenerated](../../principles/physics/shapes/index.md#autogen)* option. 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: ![](unigine_shapes.png) Colliders are also often used as [triggers](../../migration/from_unity/code.md#code_triggers) in *Unity* scripting. ### Static Collider In *Unity* software, you would create *GameObject* that has *Collider* but no *RigidBody* to create a non-moving collider. UNIGINE features two [types of collisions](../../principles/physics/collision/index.md), you can apply any option to make an object to be static collider: - ***Shape-Shape* collision**: between two objects with physical properties assigned (i.e. between their shapes). ![](shape_shape_icon.png) To create a static collider perform the following: 1. Assign *[Dummy Body](../../principles/physics/bodies/dummy/index.md)* to the node. 2. 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_icon.png) To make a mesh surface (e.g. of an *ObjectMeshStatic*) provide static collisions, just enable the **Collision** flag for it: ![](unigine_surface_collision.png) 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. > **Warning:** Don't scale meshes that are going to participate in collision detection � physics doesn't work properly with scaled objects. To avoid scaling, reimport the mesh with the required [scale](../../editor2/fbx/index.md#fbx_scale). ### 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). To create such a collider object in UNIGINE, you assign *[Rigid Body](../../principles/physics/bodies/rigid/index.md)* to it and create the required set of [Shapes](../../principles/physics/shapes/index.md) to define its collision geometry. ### 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. 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. ## 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_layers_collision.png) In UNIGINE, selective collision detection is controlled via **[Collision](../../principles/bit_masking/index.md#collision_mask)** mask of both shapes and surfaces depending on the [type of collision detection](#physics_static) used: | ![](unigine_collision_mask_shape.png) | ![](unigine_collision_mask_surface.png) | |---|---| | *Shape Collision Mask* | *Surface Collision Mask* | Two objects will collide only if their *Collision* masks match (one bit at least). ![](../../content/optimization/physics/collision_filter.gif) For more details proceed to the dedicated article: - [Physics Optimization](../../content/optimization/physics/index.md#Collision) ## Joints As well as *Unity* software, UNIGINE provides support for **[Joints](../../principles/physics/joints/index.md)** 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* software | UNIGINE | |---|---| | Character Joint | [Ball Joint](../../principles/physics/joints/index.md#ball) | | Configurable Joint | � | | Fixed Joint | [Fixed Joint](../../principles/physics/joints/index.md#fixed) | | Hinge Joint | [Hinge Joint](../../principles/physics/joints/index.md#hinge) | | Spring Joint | [Prismatic Joint](../../principles/physics/joints/index.md#prismatic), [Cylindrical Joint](../../principles/physics/joints/index.md#cylindrical) | | implemented as *Wheel Collider* | [Wheel Joint](../../principles/physics/joints/index.md#wheel), [Suspension Joint](../../principles/physics/joints/index.md#suspension) | | � | [Path Joint](../../principles/physics/joints/index.md#path) | | implemented as *Cloth Constraints* in the *Cloth* component | [Particles Joint](../../principles/physics/joints/index.md#particles) | ## Ragdoll *Unity* Editor has a simple wizard that lets you create a ragdoll by automatically generating all *Colliders, Rigidbodies* and *Joints*. In UNIGINE, **[Ragdoll](../../principles/physics/bodies/ragdoll/index.md)** 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](../../objects/objects/mesh_skinned_legacy/index.md)*. To switch between a bone-based animation and ragdoll simulation, use the **[Frame-based animation](../../principles/physics/bodies/ragdoll/index.md#enable)** feature. ## Physic Materials *Unity **Physic Materials*** contain a set of physical parameters used to adjust friction and bouncing effects of colliding objects. In UNIGINE, the **Friction** and **Restitution** parameters are available for [shapes](../../principles/physics/shapes/index.md#shape_params) and [surfaces](../../editor2/node_parameters/physics/index.md#surface_physics) and taken into account depending on the [type of collision detection](#physics_static) used: | ![](unigine_physics_friction_shape.png) | ![](unigine_physics_friction_surface.png) | |---|---| | *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. UNIGINE provides collision detection for [players](../../migration/from_unity/index.md#scene_players) as well. You can enable the **Collision** flag for *[Spectator](../../objects/players/spectator/index.md#physical), [Persecutor](../../objects/players/persecutor/index.md#control_parameters)* and *[Actor](../../objects/players/actor/index.md#physical)* 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. > **Notice:** For your convenience there are the C# and C++ samples that you can take as an example of implementing *Unity Character Controller* functionality in UNIGINE and extend it if required. ## 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. In UNIGINE, you can use **[Physicals](../../objects/effects/physicals/index.md)**. These are objects inside of which there is an invisible force field affecting physics-driven objects. The *[Physical Wind](../../objects/effects/physicals/physical_wind/index.md)* is capable of applying a constant directed force to an object. ### See Also - Video Tutorial: [Physics](../../videotutorials/essentials/physics.md)