shown in other instead.
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.
- BodyRagDoll class.
Assigning a Ragdoll Body
To assign a ragdoll body to an object via UnigineEditor perform the following steps:
- Select a skinned mesh object to assign a ragdoll body to.
- Open the Nodes window by pressing the N key.
- On the Body tab of the Nodes window select Type -> Ragdoll.
- Set body's 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.
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 done basing on the following parameters:
Bones can be approximated either with Convex hulls or Capsules, if Capsule shape box is checked:
- Capsules provide very fast physics simulation and continuous collision detection.
- Convex hulls provide more accurate approximation.
If any other shape is required, approximation is to be done manually.
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.
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.
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 dummy node 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 animation 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
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 he 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.