Physics · interface

RagdollOptions

Explained in Your first game, Rigid bodies.

interface RagdollOptions
import type { RagdollOptions } from '@driftengine/physics';

Properties

NameTypeDescription
radiusRatiooptionalnumberCapsule radius, as a fraction of the bone's length.
minRadiusoptionalnumberA floor under the radius, so a short bone is not a needle.
densityoptionalnumber
swingCosoptionalnumber | ArrayLike<number>Cosine of the swing cone allowed: one number for every joint, or one per joint.
More

It was one number for a whole body until 2026-08-28, and a body is not one joint. A knee is a hinge with no twist; a shoulder is nearly a ball. Given one pair, a consumer chooses which of the two is wrong — and the one who reported this chose loose, a 78° cone and 74° of twist at every joint, with a comment saying tight limits look like a wooden puppet. What it produced was reported from play as a scrambled ball of things, limbs torso head mixed together: at 78° nothing stops a knee or an elbow folding a limb through the torso, so a body that lands rolls itself into a knot.

An array is indexed by the joint, exactly as parents is, so the entry at the knee limits the knee: the joint a bone gets is the one at its parent end, and the bone at index j is the one below joint j. Index 0 is a rig's root, which has no bone and therefore no joint, and its entry is ignored. An index the array does not reach, or one holding anything that is not a finite number, takes the default — which matters more than it sounds, because the alternative reading of a missing entry is zero, and zero is a 90° cone at exactly the joint nobody thought about.

What this does not buy is a real hinge. A narrow cone with no twist is a near hinge: it still bends a little in every direction, because a cone is a cone. A knee that cannot bend sideways at all needs a revolute joint and an axis, and the axis is rig data this builder is never given — a parent array and a set of world matrices do not say which way a knee folds. What would change it is a consumer measuring that sideways bend as the problem, and the answer then is a joint type per bone with the axis supplied, not a wider cone.

A value here is compared every tick, so compute it the way the block below computes its defaults. Math.cos is not specified precisely by ECMAScript, so a limit built with one is a limit that can differ by a ulp between two engines, and a ragdoll that diverges. Write the numbers down.

twistSinoptionalnumber | ArrayLike<number>Sine of the half-angle of twist allowed: one number for every joint, or one per joint.
minLengthoptionalnumberBones shorter than this get no body, which is how a rig's leaf tips are skipped.
layeroptionalnumber
maskoptionalnumber
selfCollisionoptionalbooleanWhether the doll's own bones collide with each other. Default true.
More

Bones that share an end are excluded either way, and that is not a setting. Two capsules jointed end to end overlap near the joint by construction, because that is what having a radius means, so every parent and child in a doll and every pair of siblings starts interpenetrating. Left to resolve, that contact fights the joint holding them together: a consumer measured it holding settled joints 14.2 cm open, turning a body at 3.0 rad/s while it lay still, and propping it 28 cm off the road on its own thighs.

false is the cheap answer and it is measurably worse. With nothing inside the doll colliding, the cones alone do not stop a limb folding through the torso — the same consumer measured a foot reaching 15% of its resting distance from the chest, which is a foot inside the ribcage. Pass it for a crowd far enough away that nobody can see, and not otherwise.