TExcelTAD
Home › Game Physics & Animation › Joints and Ragdolls

Joints and Ragdolls

A joint is a constraint between two rigid bodies (or a body and the world) that removes some of their relative freedom. A free body in 3D has six degrees of freedom: three of translation and three of rotation. Each joint type keeps some of them and locks the rest. Doors, wheels, chains, drawbridges, cranes, vehicles and ragdolls are all rigid bodies tied together with joints.

The joint zoo

Joint Keeps Example Unity Unreal Godot Box2D v3
Fixed / weld nothing breakable glued parts FixedJoint Physics Constraint, all locked Generic6DOFJoint3D all locked weld joint
Hinge / revolute 1 rotation door, wheel, lever HingeJoint Physics Constraint, one angular axis free HingeJoint3D revolute joint
Ball / spherical 3 rotations shoulder, chain link CharacterJoint, ConfigurableJoint Physics Constraint, cone and twist limits ConeTwistJoint3D (2D: revolute)
Slider / prismatic 1 translation piston, elevator ConfigurableJoint Physics Constraint, one linear axis free SliderJoint3D prismatic joint
Distance / spring rotations, distance kept or springy rope segment, suspension SpringJoint Physics Constraint with linear drive Generic6DOFJoint3D distance joint
Generic 6-DOF anything you configure everything else ConfigurableJoint Physics Constraint Generic6DOFJoint3D (combine)

Unreal has a single configurable Physics Constraint (UPhysicsConstraintComponent) where you lock, limit or free each of the six axes; Unity's ConfigurableJoint works the same way and the other Unity joints are presets of it.

Solvers handle joints exactly like contacts: as velocity constraints solved with sequential impulses, with a position fix (Baumgarte, projection or soft constraints, see Positional Correction). The differences are that joint constraints are equalities (they can pull and push) and that there can be several per joint (a hinge removes 5 degrees of freedom).

Limits and motors

Two additions make joints useful for gameplay:

  • A limit is a one-sided constraint on the remaining freedom, like a contact: "the door angle stays between 0° and 90°". It only acts when the angle reaches the boundary and is moving outward.
  • A motor (drive) is a constraint on velocity with a maximum force or torque: "turn at -1 rad/s, using at most 15 N·m". If something blocks it, the motor gives up at the torque limit instead of breaking the simulation.

This model of a door on a hinge has both. The player kicks it open, the limit stops it at 90°, and one second in, a door closer (a motor with a modest torque) swings it shut:

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

// A door on a hinge: one angle, one angular velocity. Limits 0..90 degrees, an optional motor.
struct Hinge {
    double angle = 0, w = 0, inertia = 10;            // a 1 m wide, 30 kg door: I = m w^2 / 3
    double lower = 0, upper = 90 * 3.141592653589793 / 180;
    bool motorOn = false; double motorSpeed = 0, maxTorque = 0;

    void step(double dt) {
        if (motorOn) {                                 // motor: impulse toward the target speed, limited torque
            double impulse = (motorSpeed - w) * inertia;
            double maxImpulse = maxTorque * dt;
            w += std::clamp(impulse, -maxImpulse, maxImpulse) / inertia;
        }
        // Limits are one-sided constraints, like contacts. Solved speculatively: allow exactly the
        // speed that reaches the limit by the end of this step, never more.
        double maxW = (upper - angle) / dt, minW = (lower - angle) / dt;
        w = std::clamp(w, minW, maxW);
        angle += w * dt;
    }
    double degrees() const { return angle * 180 / 3.141592653589793; }
};

double z0(double v) { return std::fabs(v) < 0.05 ? 0.0 : v; }   // printed with 1 decimal

int main() {
    std::cout << std::fixed << std::setprecision(1);
    Hinge door;
    door.w = 3.0;                                     // the player kicks the door open (rad/s)
    for (int i = 1; i <= 180; i++) {
        if (i == 60) { door.motorOn = true; door.motorSpeed = -1.0; door.maxTorque = 15; }   // a door closer
        door.step(1.0 / 60);
        if (i % 15 == 0)
            std::cout << "t = " << std::setprecision(2) << i / 60.0 << std::setprecision(1) << " s  angle " << std::setw(5) << z0(door.degrees())
                      << " deg  w " << std::setw(5) << z0(door.w) << " rad/s" << (i == 60 ? "   <- closer motor on" : "") << "\n";
    }
}
t = 0.25 s  angle  43.0 deg  w   3.0 rad/s
t = 0.50 s  angle  85.9 deg  w   3.0 rad/s
t = 0.75 s  angle  90.0 deg  w   0.0 rad/s
t = 1.00 s  angle  90.0 deg  w   0.0 rad/s   <- closer motor on
t = 1.25 s  angle  86.8 deg  w  -0.4 rad/s
t = 1.50 s  angle  78.2 deg  w  -0.8 rad/s
t = 1.75 s  angle  64.7 deg  w  -1.0 rad/s
t = 2.00 s  angle  50.4 deg  w  -1.0 rad/s
t = 2.25 s  angle  36.0 deg  w  -1.0 rad/s
t = 2.50 s  angle  21.7 deg  w  -1.0 rad/s
t = 2.75 s  angle   7.4 deg  w  -1.0 rad/s
t = 3.00 s  angle   0.0 deg  w   0.0 rad/s

Notice the motor's ramp from 1.0 s to about 1.75 s: with a limited torque it accelerates the 10 kg·m² door gradually instead of snapping it to -1 rad/s. The limit is solved speculatively: the solver allows exactly the speed that reaches the limit at the end of the step, so the door stops on 90.0° without overshooting and without any position correction. (Box2D v3 uses the same idea for its joint limits.)

Ragdolls

A ragdoll is a character's skeleton turned into rigid bodies: a capsule or box per major bone (pelvis, spine, head, upper and lower arms and legs, usually 11–20 bodies), connected by ball joints with cone and twist limits (a shoulder swings in a cone, an elbow only bends one way). When the character dies or is hit, the animation stops driving the bones, and the physics simulation takes over. Every frame, the bone transforms are copied from the bodies back to the skeleton that the skinned mesh follows.

Setting one up in each engine:

  • Unity: the Ragdoll Wizard (GameObject > 3D Object > Ragdoll...) builds rigidbodies, colliders and CharacterJoints from the bones you assign. Toggle Rigidbody.isKinematic on the bodies and disable the Animator to switch from animation to ragdoll.
  • Unreal: the Physics Asset (edited in the Physics Asset Editor) holds the bodies and constraints for a skeletal mesh. Call SetSimulatePhysics(true) on the skeletal mesh component, or SetAllBodiesBelowSimulatePhysics for a partial ragdoll (an arm that flops after a hit).
  • Godot: select the Skeleton3D and use Create Physical Skeleton. It adds a PhysicalBoneSimulator3D with one PhysicalBone3D per bone (each with its own joint type: cone, hinge, pin, slider or 6DOF). Call physical_bones_start_simulation() on the simulator to let go.
csharp
// Unity: switch a character from animation to ragdoll (engine code, not runnable here)
public class RagdollSwitch : MonoBehaviour
{
    [SerializeField] Animator animator;
    Rigidbody[] bodies;

    void Awake()
    {
        bodies = GetComponentsInChildren<Rigidbody>();
        SetRagdoll(false);
    }

    public void SetRagdoll(bool on)
    {
        animator.enabled = !on;
        foreach (var body in bodies) body.isKinematic = !on;   // kinematic bodies follow the animation
    }

    public void Die(Vector3 hitImpulse, Rigidbody hitBody)
    {
        SetRagdoll(true);
        hitBody.AddForce(hitImpulse, ForceMode.Impulse);       // push the bone that was hit
    }
}

Ragdoll tips that save days: keep body masses within a reasonable ratio (pelvis heaviest, hands lightest, but not 100:1), give limits some slack (too-tight cone limits jitter), turn off collisions between bodies that are joined (engines do this by default), and raise the solver iterations for ragdoll bodies only.

Active ragdolls and blending

A pure ragdoll is limp. Active ragdolls (and Unreal's Physical Animation component, UPhysicalAnimationComponent) keep the bodies simulated but add joint motors that drive every joint toward the angle of the current animation pose. The character then plays its animation, but reacts physically to hits, stumbles on stairs and pushes against walls. The drive strength sets the balance between "follows the animation" and "reacts to physics":

cpp · try it yourself
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>

// An active-ragdoll arm: a 0.7 m, 3 kg limb on a shoulder joint. The animation wants it held
// horizontal (0 degrees); gravity pulls it down. A PD motor drives the joint toward the pose.
int main() {
    std::cout << std::fixed << std::setprecision(1);
    const double m = 3, L = 0.7, g = 9.81, I = m * L * L / 3, dt = 1.0 / 60, pi = 3.141592653589793;
    std::cout << "animation wants 0.0 deg\nstrength kp | after 0.5 s | after 2 s | wobble in the last 0.5 s\n";
    for (double kp : {0.0, 20.0, 100.0, 400.0, 2000.0}) {
        double kd = 2 * std::sqrt(kp * I);             // critically damped drive
        double angle = 0, w = 0, at05 = 0;              // radians, 0 = horizontal, negative = down
        double lo = 10, hi = -10;
        for (int i = 1; i <= 120; i++) {
            double gravityTorque = -m * g * (L / 2) * std::cos(angle);
            double motorTorque = kp * (0 - angle) - kd * w;
            w += (gravityTorque + motorTorque) / I * dt;
            angle += w * dt;
            if (angle < -pi / 2) { angle = -pi / 2; w = 0; }       // joint limit: hanging straight down
            if (i == 30) at05 = angle;
            if (i > 90) { lo = std::min(lo, angle); hi = std::max(hi, angle); }
        }
        std::cout << std::setw(11) << kp << " | " << std::setw(7) << at05 * 180 / pi << " deg | " << std::setw(5) << angle * 180 / pi << " deg | " << std::setw(5) << (hi - lo) * 180 / pi << " deg\n";
    }
}
animation wants 0.0 deg
strength kp | after 0.5 s | after 2 s | wobble in the last 0.5 s
        0.0 |   -90.0 deg | -90.0 deg |   0.0 deg
       20.0 |   -23.6 deg | -26.4 deg |   0.0 deg
      100.0 |    -5.8 deg |  -5.9 deg |   0.0 deg
      400.0 |    -1.5 deg |  -1.5 deg |   0.0 deg
     2000.0 |    12.0 deg |  12.0 deg | 102.0 deg

With no drive, the arm hangs straight down at the joint limit (a dead ragdoll). A weak drive lets gravity win by 26°, which looks tired. At kp = 400 the arm follows the animation within 1.5° and would still give way to a hit. The last row is a warning: this hand-written PD motor is an explicit spring, and at kp = 2000 it breaks the stability limit from Springs and Damping at 60 Hz, so the arm shakes through 100° every frame. Engine drives are solved implicitly, so they get stiff rather than explode, but very stiff drives still fight the contacts and jitter.

The other common transition is ragdoll to animation ("get up"): when the ragdoll comes to rest, pick a get-up animation that matches whether it lies face up or face down, then blend the bone transforms from the ragdoll's final pose to the animation over 0.2–0.5 s (see Blending Poses and Quaternions).

Test yourself

Which joint type is a door hinge?

  1. Ball (spherical)
  2. Revolute (hinge): one rotational degree of freedom
  3. Prismatic (slider)
  4. Fixed

What does the maximum torque of a joint motor do?

  1. Sets the target angle
  2. Limits how hard the motor can push, so it gives up instead of breaking the simulation when blocked
  3. Sets the joint's mass
  4. Disables the joint limits

How does an active ragdoll follow an animation while staying physical?

  1. It teleports bones to the animation every frame
  2. Joint motors drive each joint toward the animated pose with a finite strength
  3. It disables gravity
  4. It switches the bodies to kinematic