Guide
Game inverse kinematics explained
Harbor Ruins' archer looked polished in the mocap suite — until playtesters strafed along a ruined staircase and the bow string floated six inches from the grip while the left foot hovered above a cracked step. The locomotion blend tree was fine; the problem was that keyframed clips alone cannot adapt every bone to uneven ground and a moving aim point. The fix was inverse kinematics (IK): solvers that work backward from a desired end-effector position (foot on the floor, hand on the bow grip, head toward the reticle) to compute joint rotations. After adding two-bone leg IK with raycast foot targets, spine-aim toward the camera reticle, and a short pole-vector constraint so elbows did not invert, foot slide complaints dropped 78% and ranged combat feel scores rose in blind tests. IK is the bridge between authored animation and environmental reality. This guide covers forward vs inverse kinematics, analytic two-bone solvers, iterative CCD and FABRIK, foot planting and look-at patterns, engine tooling in Unity and Unreal, a Harbor Ruins archer refactor walkthrough, a method decision table, common pitfalls, and a production checklist.
Forward kinematics vs inverse kinematics
In forward kinematics (FK), you rotate joints from root to tip and the end effector (hand, foot, muzzle) lands wherever the hierarchy places it. Animation clips are FK data: each frame stores bone rotations; the engine multiplies transforms down the chain. FK is predictable, fast, and artist-friendly for expressive motion.
Inverse kinematics (IK) inverts the problem: you specify where the end effector should be (or what it should look at), and the solver computes joint angles that reach that goal while respecting bone lengths and optional constraints. IK does not replace FK clips — it layers on top. A strafe cycle might drive the pelvis and upper legs via FK while IK pulls each foot to a ground hit from a downward raycast.
Games use IK wherever the world is more variable than a single mocap take: slopes, stairs, cover heights, weapon grips, seated poses on props of different sizes, and camera-relative aim. Without IK, you author dozens of corrective clips or accept visible foot float and misaligned props.
Two-bone analytic IK
The most common game IK problem is a three-joint chain with fixed segment lengths: hip–knee–ankle, shoulder–elbow–wrist, or root–mid–tip. Analytic two-bone IK solves this in closed form using the law of cosines.
Given root position R, target T, upper length
L1, lower length L2, and a pole vector
(hint for which side the joint bends toward), the solver:
- Clamps
Tto reachable range if it lies outside|L1 − L2|toL1 + L2. - Computes the angle at the middle joint from the triangle formed by
R,T, and the elbow/knee. - Rotates the upper bone toward
Tand applies the middle joint bend, using the pole vector to disambiguate the two mathematical solutions.
Two-bone IK is O(1), stable, and implemented in every major engine
(Animator.SetIKPosition in Unity, TwoBoneIK nodes in
Unreal's Control Rig). Use it for legs, arms, and simple weapon aim chains.
The pole vector is not optional in production — without it, knees and elbows
flip unpredictably when the target crosses the limb plane.
Iterative solvers: CCD and FABRIK
Longer chains — spines, tails, tentacles, multi-segment ropes — rarely have closed-form solutions. Iterative methods approximate IK over a few passes per frame.
Cyclic Coordinate Descent (CCD)
CCD rotates each joint from tip toward root so the end effector points at the target, one joint at a time, repeating for several iterations. It is easy to code and works on arbitrary hierarchies, but joints near the root can over-rotate while distal joints barely move, producing unnatural “curling” on long chains unless iteration counts and angle limits are tuned.
FABRIK (Forward And Backward Reaching IK)
FABRIK treats the chain as rigid segments connected by joints. It positions the tip at the target, then pulls each joint back along the segment lengths toward the root (backward pass), then re-anchors the root and pushes joints forward (forward pass). After a handful of iterations, the chain conforms smoothly. FABRIK tends to look more natural on spines and tentacles than CCD and is the default choice in many middleware rigs.
Both methods need joint limits (min/max angles per axis) in games. Unconstrained iterative IK will fold limbs backward for dramatic effect unless clamped.
Foot IK and ground adaptation
Foot slide is the signature failure mode of in-place locomotion clips on non-flat terrain. The standard fix is a per-foot IK pass after the animation graph evaluates:
- Raycast or sphere-cast from hip height downward to find ground position and normal.
- Set the ankle IK target to the hit point, offset by foot bone bind-pose height.
- Rotate the foot to align with the ground normal (often slerp toward target orientation to avoid twitch).
- Apply pelvis offset (hip drop) so the shorter leg does not stretch — distribute half the correction to each leg when both feet are planted.
Blend IK weight by gait phase: full weight when the foot is planted (contact curve > 0.9), fade to zero during swing phase so toe-off animation is not fighting the solver. Pair with locomotion root-motion vs in-place decisions — IK corrects feet; it cannot fix a pelvis that drifts meters from intended speed.
On stairs, use multiple short raycasts or capsule sweeps rather than a single ground plane. For multiplayer, ground hits must be deterministic from replicated world geometry, not client-only decorative meshes.
Look-at, aim, and hand IK
Look-at IK rotates spine, neck, and head bones so the character's eyes (or weapon forward axis) track a world or screen-space target. Production pattern:
- Clamp total yaw/pitch so characters do not exorcist-spin behind themselves.
- Distribute rotation across three spine bones + neck + head with weighted falloff (40/30/20/10% typical) for organic motion.
- Blend IK weight with combat state — full aim in ADS, partial in hip-fire, zero during reload montages driven by FK.
Hand IK snaps wrists to weapon grips, ladder rungs, or steering wheels. Offset targets come from socket transforms on props. When the prop moves (vehicle, moving platform), IK targets update in world space each frame. For two-handed weapons, solve the dominant hand first, then position the support hand with a shorter two-bone chain toward a secondary socket.
Engine tooling: Unity and Unreal
Unity exposes per-bone IK through the Humanoid
OnAnimatorIK callback (SetIKPositionWeight,
SetIKRotation for feet and hands). Animation Rigging package adds
multi-chain constraints (Two Bone IK, Multi-Position, Chain IK) as playable
graph layers. Rig Builder runs after the base Animator, which keeps mocap clips
intact while constraints override extremities.
Unreal Engine offers IK nodes in AnimGraphs (two-bone IK, FABRIK, CCD) and Control Rig for editor-authored solvers. Virtual bones bridge skeleton gaps. Aim offsets and Look At nodes handle head tracking with built-in clamp curves.
Custom engines often implement two-bone IK in the pose graph after clip evaluation, before skinning. Profile IK in the same budget as animation update — ten characters with four two-bone solves each is cheap; fifty creatures with 12-bone CCD at 8 iterations is not.
Harbor Ruins archer refactor (worked example)
Harbor Ruins is a third-person action prototype. The archer's problems clustered on ruined terrain and free aim:
- Foot float on rubble. Strafe clips were in-place. Added per-foot raycasts from knee + 0.2 m, two-bone IK to hit point, foot normal alignment at 70% slerp, pelvis drop capped at 8 cm. IK weight driven by planted-foot curve from the blend tree.
- Bow hand separation. Draw-and-release montage was FK-only. Added left-hand two-bone IK to a socket on the bow mesh during aim and release states; weight 0 during full draw montage to preserve authored tension.
- Spine aim vs camera. Reticle sat at screen center; spine chain (3 bones) received look-at toward camera forward ray at 10 m. Yaw clamped ±70°, pitch ±35°. Weight scaled by aim input magnitude.
- Elbow pop. Elbow inverted when aiming over left shoulder. Pole vector set to character's left hip offset; stable across 360° strafe.
QA pass on 15 rubble-heavy encounter zones: foot penetration bugs fell from 23 to 4 (remaining cases were missing collision on decorative debris, fixed in physics layer). No measurable frame-time regression on target hardware — four analytic IK solves per character per frame.
IK method decision table
| Problem | Recommended approach | Why |
|---|---|---|
| Foot on uneven ground | Two-bone leg IK + raycast + pelvis offset | Closed-form, fast, artist-tunable blend weights per gait phase |
| Hand on weapon grip / prop | Two-bone arm IK to socket transform | Exact position lock; pairs with FK upper-body montages |
| Head / weapon look-at | Weighted spine chain rotation with clamps | Avoids single-neck twist; distribute across vertebrae |
| Long tail, tentacle, rope | FABRIK or CCD with joint limits | No analytic solution; iterative passes converge visually |
| Full-body reach to moving target | Animation Rigging / Control Rig multi-chain | Engine constraints handle priority and blend to FK |
| Death collapse, physics ragdoll | Ragdoll physics blend, not IK | IK fights simulation; blend out FK into passive joints |
Common pitfalls
- Missing pole vectors. Elbows and knees flip when the target crosses the limb plane; always author a stable hint (hip offset, knee forward vector).
- IK during swing phase. Pulling a moving foot to stale ground hits causes skating; gate weight by contact curves or foot speed.
- Over-constraining spines. 100% look-at IK on a single neck bone looks robotic; distribute and clamp.
- Unreachable targets. Stretching bone lengths when targets exceed chain reach causes mesh tearing; clamp target distance before solve.
- Ignoring bind-pose offsets. Foot bones rarely sit at ankle pivot; apply authored offsets when placing IK targets.
- Network desync. IK driven from client-only ground causes foot mismatch in multiplayer; replicate hits or use shared collision.
- Fighting root motion. Pelvis driven by root-motion clips plus aggressive foot IK doubles translation; choose one primary driver.
- CCD without limits. Long chains fold into pretzels; per-joint angle clamps are mandatory.
Production checklist
- Identify end-effector goals per character state (planted foot, grip, aim).
- Implement two-bone analytic IK with pole vectors before iterative solvers.
- Raycast ground from consistent heights; validate collision on all walkable art.
- Blend IK weights by animation phase curves, not binary on/off.
- Clamp look-at and aim to plausible human ranges per bone.
- Profile IK cost per character at worst-case crowd density.
- Test 360° aim and strafe on stairs, slopes, and moving platforms.
- Verify multiplayer foot placement matches across clients.
- Blend IK out before ragdoll handoff on death.
- Document socket transforms on weapons and interactive props.
Key takeaways
- IK solves joint angles backward from desired end-effector positions; FK clips still drive the base motion.
- Two-bone analytic IK handles most game limbs at O(1) cost with pole vectors to prevent joint flips.
- Foot IK plus pelvis offset eliminates most terrain foot-float without reauthoring every slope clip.
- Look-at and hand IK need clamps, weighted spine distribution, and state-based blend weights.
- Gate IK by gait phase and profile cost before scaling to crowds or long iterative chains.
Related reading
- Game animation blending explained — blend trees, layers, and where IK sits in the graph
- Game locomotion explained — controllers, root motion, and ground probes
- Game ragdoll physics explained — when to blend out IK into simulation
- Game camera systems explained — reticle aim and camera-relative targeting