09/28/2022
Use physic engine to generate real-time animation -- Just like what we did in real life!
Advantage: Realistic interaction with objects in the scene.
Generally, producers use animators for general cases and Ragdoll physics to simulate the character's death animation.
There are some games that use Ragdoll physics all time, e.g. Party Animals.
Note: The unity version I used is 2021.3.6f1; and it is recommended to run Unity between each step to see closed how we build the ragdoll step by step.
Import a 3D character, for the sample case, I just build it with several base geometries.
2. Properly assign colliders to each body part; You may use Window -> Analysis -> Physics Debugger to view the composited collider.
3. In its core joints (e.g. Hip; Head; Shoulders/Legs), add the configurable joint component, a rigidbody component should be automatically added with it.
4. Connect body parts by properly assigning their Connected Body (e.g. hand -> elbow -> shoulder -> spine -> hip). Note: The HIP should be the center of the body, and the other main parts should finally connect to the hip, while the hip itself does not need to connect to others.
In the example case, just simply connect all parts to the hip.
5. For all joints, we lock their XYZ motion (prevent body part from splitting), and set the Position Spring of the Angular XYZ drive to 200 (assign the spring to make the ragdoll stand up, a larger drive is required for a larger mass of the ragdoll).
6. The hip is generally the center of a ragdoll, hence we want this part to connect to all other parts and be the power source: We unlock the XYZ motion of the hip.
7. We are almost done, the final step is to assign a new physics layer to our ragdoll to prevent the self-collision of the body parts.
8. Run the game, and drag the father node of the ragdoll to check your result!
It is simple to schieve the effect: Just disable the animator (if has), then set the position spring of all body part (or just the hip itself, based on your demand) to 0.
Unity does provide tools to generate ragdoll, view the manual for more details.
Just like Party Animal did, we could use ragdoll animation to make realistic visual effects, for more details, view this passage:
Combine Ragdoll and Animator to generate realistic animation