Ragdoll system

Rag Doll system, I believe many players have encountered in most games. As a mature and popular system, Ragdoll is widely used in a variety of games to provide some degree of physics simulation.

In a typical Ragdoll scenario, the enemy rolls over and falls to the ground after being punched in the air. The process is very natural and smooth. And, in the whole process, there is no traditional “animation”, everything is based on physical simulation effects. Therefore, the doll system is also an important means of “procedural animation”.

Model and Skeleton

model

To understand why Ragdoll works as well as physics animations, we need to take a quick look at how animations are implemented in traditional 3D games. (If you already know, you can skip to the next section.)

As the most commonly used art resource, the model itself is a data set composed of a series of vertex (coordinate) information. Therefore, it is obvious that a pure model is purely static. Check the Selection Wire in Unity->Gizoms to see the wireframes of the model. In Unity, you can see the Mesh Renderer family of components, where the Mesh is the Mesh of the model.

So to make the model move, what we need to do is to make each vertex of the model move in accordance with certain rules to achieve the “animation” effect, which is also the classic “vertex animation” principle.

However, in modern games, where a slightly complex model often has thousands of vertices, it is impractical for artists to manually set the motion of each vertex, and it is difficult to achieve a reasonable effect.

So people think of the reality that humans rely on bone to drive muscle movement, we rarely directly control the movement of a muscle in the body, more to drive the bone. As long as the skeleton moves according to certain rules, the muscles attached to the skeleton will also move accordingly, and the concept of bone animation came into being.

bone

“Skeleton” is actually an abstract concept, which refers to the law of human body using bones to drive muscle movement, and creates a similar and abstract “skeleton” for the model, as shown in the figure.

This is a model that contains bones, which are visually displayed using BoneRenderer in AnimationRigging (otherwise bones are an abstract concept that doesn’t correspond to visible objects). As you can see, the model skeleton is very similar to the human skeleton, only simplified to a certain extent.

In fact, bones in Unity are just a series of empty objects with hierarchical relationship between father and child. The hierarchical structure refers to reality to some extent. The father skeleton can drive the movement of child bones (for example, when we lift the thigh, the calf will follow the thigh). From the parent bone to the child bone, you get the visualized bone shape in the image above, which makes it easier to show the shape of the bone.

In the figure, Armature represents the hierarchical skeleton, and body is the character model, which again indicates that the model is separated from the skeleton.

skin

Skin is the process of attaching the vertices of the model to the skeleton, which determines which “muscles” are controlled by which “bones”. After establishing this binding relationship, when we drive the arm “skeleton”, the vertices of the arm will also move, thus simplifying the control of the “vertex” movement in animation to control the “skeleton” movement.

The skin information of the vertex includes which bones (there can be more than one) the vertex is affected by, and the weight of each bone. In this way, in the process of some complex movements, the vertex can follow the track of changes more delicate and real, and at the same time, it can eliminate some tears at joint joints.

A Skinned Mesh Renderer is used in Unity to achieve this effect.

Skeletal animation

Once we have a skinned character model, we only need to control the bone movement to move the vertices of the model. The animation data actually records the position and rotation information of each skeleton in each key frame. At the same time, some algorithms are used to interpolate between key frames to achieve smooth movement of bones. (This part is generally produced by animators in professional software, commonly known as K animation, also known as K key frame)

The picture shows the information of an animation file. You can see the position information of each skeleton in each key frame. With these preparations, our model is ready to move.

Ragdoll

Ragdoll’s philosophy is easy to understand once you understand traditional bone animations. To add Ragdoll effects to a character, you simply mount appropriately sized colliders and rigid body components on the skeleton, and make the skeleton movement driven by physical simulation (rather than animation) to achieve a physics-based Ragdoll system.

Unity native Ragdoll

Ragdoll is available in Unity nativity. You can right click on Prefab -> 3D Object -> Ragdoll…

It should be noted that the skeleton is generally based on the hip joint. After it is configured below the waist of the character, Unity will automatically generate the collision body of each limb. After that, we can manually adjust the shape of the collision body to fit the model

When we run the game again, the character collapses like a Rag Doll.

Unity’s native ragdoll system is so simple that you can click on a skeleton node that has a collider in it. As you can see, the limb skeleton only adds a RigidBody and Collider for the physical simulation, and the limb simulation joint is connected with the CharacterJoint, and the rest is handed over to the Unity physics system for simulation.

The native Ragdoll system is inadequate

After looking at the Unity Ragdoll system, it is clear that the system is relatively simple and has a lot of shortcomings

  • Collision body, rigid body and other components are directly mounted on the skeleton, which affects the simplicity of the skeleton structure and increases the coupling degree
  • The lack of an Animator component means that Ragdoll is purely physics driven and cannot be integrated with animations (hence Unity’s official recommendation to use Ragdoll only when a character dies).
  • State transitions are difficult, difficult to scale, and lack of transitions (e.g., changing collider and rigidbody parameters while enabling multiple ragdoll representations)

Ragdoll Mecanim Mixer

The Ragdoll Mecanim Mixer is designed to address these pain points, and provides a good solution to each of these problems. (The plugin is available on the Asset Store and is currently one of Unity’s best Ragdoll plug-ins.)

  • Ragdoll colliders are separated from bones, not directly related, and reduce coupling
  • Based on the separated structure, physical transformation and animation transformation can be calculated and fused respectively
  • Multiple states can be preset based on a Ragdoll collider, with easy switching and controlled transition smoothness

The official document: assetstore. Altinqiran. Kz/ramecan – mix…

The plug-in consists primarily of two scripts

  • Ragdoll Constructor
  • Ramecan Mixer

Ragdoll Constructor

This script is used to configure the Ragdoll collider for the character and related information. Once the script is mounted, we first need to choose which skeleton to create the collider for. The rules are basically the same as those of Unity’s native Ragdoll. After selection, we can manually create a Ragdoll Avatar (Scriptable Object) to save the configuration information (select the existing configuration to avoid repeated Settings).

Then we can set the size of the collider, the mass, the range of motion of the joint and so on for each bone

Once you configure Create, you can see a container outside the Player in which Ragdoll is managed as a separate object, decoupled from the role itself

Ramecan Mixer

After Ragdoll is created, we can see that a RamecanMixer component is automatically added to the Player. This component is mainly responsible for controlling various state transitions and animation fusion functions. Detailed parameters for each skeleton can be configured, which can be easily understood by referring to official documentation

  • When Ragdoll physical effect Is not needed, Is Kinematic and Only Animation can be selected, which are completely driven by Animation
  • When Ragdoll physical effect Is Kinematic Is deselected, detailed parameters and Angle limits of each skeleton can be configured
  • See the last section for parameter configuration reference (simulated corpse)

After configured, we can add a new state of preservation, after can use scripts to control switch RamecanMixer. BeginStateTransition (Name)

You can see the fine physics

Analysis of the principle of RamecanMixer

RamecanMixer plug-in can realize ragdoll and bone separation, animation fusion and other effects. Its physical simulation is still based on Unity physics engine, mainly because of its new fusion algorithm, which is not difficult to understand

In bone.cs we can see a detailed definition of the Ragdoll skeleton, with two parameters to note

  • animTransform
  • physTransform

Obviously, the Ragdoll skeleton records the current animation-driven skeletal Transform (the model skeleton) and the physically-driven Ragdoll skeletal Transform (a series of colliders under the Ragdoll object).

In RamecanMixer.cs, it can be seen that the realization of physical effects and integration with animation mainly follows the following process

  • The physical calculation of RigidBody in FixedUpdate() is mainly to “bridge” the gap by applying force to RigidBody when there is a deviation between RigidBody and the animation skeleton, so as to achieve the “inertia” effect of the object
  • Update() does a simple assignment that records the transformation of the last frame of the animated skeleton
  • LateUpdate() is a core animation fusion operation that interpolates the rigidbody transform of the previous frame with that of the current frame to achieve a smooth transition

Those interested can peruse the plugin’s source code, which is annotated to make it easier to understand

Ragdoll parameter configuration tips

The Ragdoll implementation principle is described above, but in order to achieve a good simulation effect, each skeleton needs to be configured in detail, and at the same time, patient debugging, finally to achieve the desired effect. Here is a reference for some important parameters, mainly for the simulation of character death effect

Quality ratio

To achieve better doll effect, the most important thing is the quality distribution of each skeleton, and it is suggested that the quality distribution of the actual human body is the benchmark

  • Head — 7.30%
  • Torso (chest, back and abdomen) — 50.80%
  • Thighs — 9.88%
  • Calf — 4.65%
  • Upper arm — 2.7%
  • Forearm — 1.60%
  • Feet – 1.45%
  • Hand – 0.66%

Thigh and other limbs, all refer to a single mass. It is reasonable to set the total body weight between 60 and 100KG

After studying Naughty Dog’s lecture on Ragdoll (Physics Animation in Uncharted 4: A Thief’s End) at GDC2017, they have A rule of thumb for mass distribution

The Ragdoll bone mass is not strictly based on the actual distribution of body mass, but multiplied by a percentage of actual mass, which starts at the hip and decreases up and down. It’s actually more intuitive than the Ragdoll bone mass

RamecanMixer parameters

  • Open the self Collision
  • Rotation Accuracy set to 0.2 or less (to ensure joint flexibility)
  • Angle restriction is opened (specific Angle has been configured in the Construct stage, it is suggested to refer to the movable range of human joints)
  • The Spring Rotation in the Joint Drive is set to a low value to ensure that joints can swing. A higher value will lead to hard joints (they will try to bounce back to their original form).

conclusion

Ragdoll effects are relatively easy to implement in Unity, especially with existing plug-ins, and the main thing to do is to configure the Ragdoll parameters in detail to make them look the way we want them to look. Then I will use this system to study the physical fusion of Ragdoll with other actions (such as climbing, etc.) in addition to death animation, hoping to achieve the physical effect of Naughty Dog in Shenhai4

Naughty Dog GDC Reference link: www.youtube.com/watch?v=7S-…