RagDoll Body
RagDoll body enables inverse kinematics and procedural animation of a death sequence for bone-animated characters. This type of body is actually a set of Rigid bodies representing each bone of a character linked together by joints. These joints restrict movement of the bones relative to each other, providing realistic look.
See also#
- BodyRagdoll class
- Fragment of the video tutorial on physics illustrating inverse kinematics of a RagDoll body
Assigning a RagDoll Body#
To assign a RagDoll body to an object via UnigineEditor perform the following steps:
- Open the World Hierarchy window.
- Select a Mesh Skinned object to assign a RagDoll body to.
-
Go to the Physics tab in the Parameters window and assign a physical body to the selected object by selecting Body -> RagDoll.
- Set the body name and refer to the next section to create a RagDoll.
Creating a Physical RagDoll#
There are two ways of creating a RagDoll:
- Automatic generation.
- Manual creation.
After the body is assigned to the Mesh Skinned, the first step is to create a Rigid body that will represent each bone in physical simulation.
For now, all the bones are free, meaning there is no Rigid body associated with them. To automatically generate a RagDoll, i.e. rigid bodies and approximating shapes along with joints to connect them, Create button should be clicked.
Automatic generation is performed on the basis of the following parameters:
Approximation Shape#
Bones can be approximated either with Convex hull or Capsule, if Capsule shape box is checked:
- Capsule provides very fast physics simulation and continuous collision detection.
- Convex hull provides more accurate approximation.
If any other shape is required, approximation is to be done manually.
Total Mass#
Total mass of the RagDoll will be automatically distributed among all the shapes that approximate bones. By distribution, the volume that the shape occupies is taken into account. If the mass is changed afterwards, all the shapes masses are recomputed. And the opposite way, if shape mass is changed, the total mass is modified correspondingly.
Approximation Error#
If convex hulls are used to approximate bones, the result may contain too much detail for collision geometry. As a rule, it is unnecessary, because a highly detailed shape does not provide noticeable visual difference while significantly affecting performance. Approximation error makes it possible to control the number of vertices in the resulting convex hull:
- The lower the value, the more accurate and close to the mesh approximated shape is.
- The maximum value of 1 provides quite rough approximation that may not cover all the mesh volume.
If a character is approximated with capsules, low value of approximation error provides more precise shape orientation.
Volume Threshold#
When creating a RagDoll, small bones (like finger bones, for example) are rarely simulated. They are too insignificant to change the motion of the whole object, as their mass and volume is not sufficient for that. Volume threshold allows to merge all small adjacent bones, the volume of which is too small, into one shape:
- By the minimum value of 0, all the bones without exception are represented in rigid bodies and hence shapes.
- By the maximum value of 1, approximation shapes are big and follow only the major bones. Small bones are included in this volume, but their individual transformations are not considered in physical simulation.
Volume threshold defines whether all bones up to the smallest one should be simulated separately or merged into bigger shapes
|
Body Hierarchy for Bones#
After a RagDoll has been created, all the bones that are represented in rigid bodies and shapes and specify their movement are marked as bound in the hierarchy. All the small bones not participating in physical body movement, stay marked as free. If automatically generated shapes are too loose, they can be tuned manually till approximation is satisfying enough.
Hierarchy of bodies and shapes that approximate bones can be saved into a .node and loaded from one. The set hierarchy can as well be removed from the RagDoll body and created anew.
Manual Creation of a RagDoll#
It is also possible to create a RagDoll manually. In this case arbitrary shapes can be used to approximate bones of a RagDoll body. To create a RagDoll manually follow these steps:
- Create a Node Dummy that will be a parent node for future RagDoll hierarchy.
- Add a Dummy Object and make it a child node. Assign a Rigid body to it and name the body after the bone it will represent. After that, approximate the bone with any necessary shape.
- Create all Rigid bodies and shapes for the RagDoll bones. Hierarchy is of no importance, only names of the bodies do.
- Export the parent node into the .node file.
- Select the character and load this file for its RagDoll body.
- Add and set up joints that connect rigid bodies within the RagDoll.
Enabling RagDoll Animation#
When the character hits some obstacle or, for example, he is shot and dies, it is necessary to turn off bone-based animation playback and simulate the character realistically falling according to the physical laws. When the Frame-based box is unchecked, RagDoll body is no longer driven by the bone transformations. It collapses according to Rigid body dynamics (masses of all rigid bodies, that represent parts of a RagDoll, velocity damping, etc.), joint constraints and Rigidity of motion.
Rigidity of Movement#
The Rigidity parameter allows to additionally constrain the motion of a RagDoll. It determines how uniform the motion of RagDoll parts is. To achieve that, both linear and angular velocities of each separate rigid body are corrected according to the total velocities interpolated from all the bodies.
- By the minimum value of 0, all RagDoll parts represented in rigid bodies move independently and unrestricted (of course, except for joint constrains). This gives an impression of loose and floppy movement.
- By the maximum value of 1, RagDoll parts move in a uniform and stiff manner, which may seem over-constrained.
Combined Animation and Inverse Kinematics#
The problem with pre-backed animation is that it does not offer proper environmental interaction. For example, when walking up or down the hill, character's feet do not land firmly on terrain. Or as it climbs the ladder, the hands have to tightly grab the rungs. This effect is achieved with combined animation: motion animation is played for the basic bones, while smaller bones (feet or hands, for example) are simulated physically.
Frame-based animation can be disabled for each of the rigid bodies that approximate bones. Instead of following specific bone transformation, rigid body sags loose under its own weight and connects to collider objects underneath it.
For instance, physically-driven motion of the leg requires disabling bone animation of the whole limb: thigh, calf, and foot. Inverse kinematics allows to properly position the chain of bones given the position of the lowest bone in the hierarchy, the foot. So when the character walks or runs, his foot collides with the ground, while the knee bends and straightens according to the joint constrain.