Skip to content

Inverse kinematics

Inverse kinematics (IK) computes the joint rotations needed for a chain’s tip to reach a target — the inverse of forward animation. The copied ik capability provides IKChain (src/lib/ik/ik-chain.ts in any project with the capability; the shooter examples are worked users), wrapping Three.js’s own CCDIKSolver. Its flagship use is the held-item grip convention’s off hand: the drivers point an IKChain at a held item’s Foregrip node so the second hand makes real contact — see the humanoid skill’s “Held items” section.

A bone chain bends so its effector tip reaches a target
The chain bends each frame so its effector reaches the target.

IKChain operates on a subtree containing a SkinnedMesh. Configure it, call init() once, then call update() from the owning component’s useFrame after clip sampling and procedural posing. It bends a named chain so the effector reaches an ordinary hierarchy object or world-space position. TwoBoneIK adds the familiar root/middle/tip chain and pole target.

Important inputs:

  • boneNames — bone names from chain root → effector (the tip that reaches the target).
  • targetBoneName — the skeleton bone used as the IK goal. If no bone with that name exists, one is appended to the skeleton (and the skin’s bone buffers grown) — so IK works on any rig.
  • targetOffset — a world-space target position to use when no live target is provided.
  • iterations — CCD solver iterations per frame.
  • targetObject — an ordinary Object3D used as the hierarchy-visible goal.
  • poleObject — the bend-direction control for Two Bone IK.