Skip to main content

AnimatedRagdoll

A class in Root.Township, the global namespace.

Drives a physics ragdoll to follow an animated skeleton: each ragdoll bone has a ConfigurableJoint whose slerp drive targets the matching animated bone's rotation, and the root is pulled to the animated root.

Constructors​

MemberWhat it is
AnimatedRagdoll()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

10 private and internal fields
MemberWhat it is
private Transform animatedSkeletonRootSetup only: root of the animated skeleton. Setting it with ragdollSkeletonRoot rebuilds bones and clears it.
private AnimatedRagdoll.Bone[] bonesPer bone: the animated transform, ragdoll rigidbody and joint, plus torque, damping, force and mass multipliers.
private ColliderGroup collidersCollider group for the ragdoll. Not read in this class.
private float dampeningBase joint drive damper, scaled per bone.
private Quaternion[] initialRotationEach bone's starting rotation in joint space, used to work out target rotations.
private Quaternion[] jointToLocalInverse of localToJoint per bone.
private Quaternion[] localToJointPer bone, the rotation from bone space to the joint's axis space.
private float maximumForceBase joint drive force limit, scaled per bone.
private Transform ragdollSkeletonRootSetup only: root of the physics skeleton that bones are matched in.
private float torqueBase joint drive spring, scaled per bone.

Methods​

4 private and internal methods
MemberWhat it is
private void Awake()Works out each joint's local-to-joint rotation and initial rotation, and loosens the root joint so it can move.
private void FixedUpdate()Moves the root joint's anchor to the animated root and sets every joint's drive strength, mass scales and target rotation.
private void OnEnable()Snaps the ragdoll bones to the animated pose and records it as the initial rotation.
private void OnValidate()Editor setup: when both skeleton roots are set, rebuilds the bone list by matching names and adds rigidbodies and locked joints, then clears the roots.