Physics
Unigine real-time physics integrates collision detection, fracturing, buoyancy, joints and external physical forces to realistically simulate objects and complex interactions between them.
Physics simulation in Unigine is based on rigid body dynamics and is calculated for dynamic objects. Dynamic objects differ from static ones in that they have:
- Physical body (or bodies)
- Collision shape (or shapes)
Static objects do not have associated physical bodies, hence, no forces can be applied to them, and they are immovable. However, they still participate in contacts with dynamic objects and prevent physical bodies from going through.
Adding Physics
To ensure consistent frame rate, simulation is based on the approximate and simplified calculations (though there are a lot of parameters like linear and rotational velocities, acceleration, friction, applied forces, etc.). Remember, it is not real world physics, but rather fake physics with sufficient precision that looks convincing.
- Do not scale any meshes in the world (static ones and physical objects) if you are going to simulate physics! Otherwise, collisions will not be calculated properly.
- Physics approximation (i.e. approximation of objects by shapes) does not need to be absolutely accurate. Approximating with spheres instead of convex hulls is strongly recommended.
See Adding physics for object tutorial for step-by-step guidance.
Global Physics Settings
Physics is simulated with its own FPS and is in effect within Physics simulation distance. (The rendering FPS can also be capped by the physics one). All other global physics-related settings are found in the Physics settings.
Physical Interaction
Most objects are not static decorations placed in the scene, they actively interact with each other, as the real object is the object of physics. It is unnatural and quite disappointing for the viewer to see the solid object inappropriately penetrating another one. Increasing the level of realism is thus unthinkable without proper approximation of the physical properties. On the other hand, there are still objects that do not require comprehensive modelling of their dynamics. The same duality goes for objects composite of many surface shapes. To compromise this fact, physical interaction is enabled on per-surface basis.
Collision Detection
Occupying a certain area in space, bouncing off the obstacles and even simply staying on the ground requires the collision detection. After checking the collision box, the surface participates in detecting, whether other objects come in contact with it and reacts correspondingly to the specified settings.
Collision Mask
For the collision detection to be more selective and at the same time alleviate the computational load, collision mask is set. For example, the object is indifferent to other objects actions and does not contribute to physical picture of the virtual world. Still, we want it to lie on the terrain, not to fall through it. Matching the bit masks of this object and the terrain (at least one bit in the masks should match), will get the desired effect.
Intersection Detection
Intersection serve a little different purposes, than collision. Intersection ray from one point to another allows lightweight and faster computing, if the surface is intersected. For example, computing collision of car wheels takes time and decreases manoeuvrability. If intersection will be used, the wheels are not represented with the properly reacting physical spheres, but rather rays, coming from the car body to the ground. And the problem of the plausible simulation will be solved.
Intersection Mask
Bit intersection mask allows to define the exact objects to be considered, when computing intersection, and disregard all the others, that have unmatched masks. It is a flexible tool, because only one bit in the masks should match. That means one object can easily participate in several different intersections simultaneously.