Inverse Kinematics (IK) is the process of calculating the joint parameters needed to place the end of a kinematic chain (like a hand or foot) at a specific target. FABRIK (Forward And Backward Reaching Inverse Kinematics) is a highly efficient, heuristic-based method that is the industry standard for games.
Traditional IK uses complex matrix calculus (Jacobians) which is computationally expensive and prone to “singularities” (where the math breaks). FABRIK is:
FABRIK treats the limb as a series of points connected by fixed-length bones. It solves the position in two phases:
Repeat these two phases 3-10 times for a pixel-perfect fit.
void SolveIK(Vector3 target, int iterations = 5) {
float[] lengths = GetBoneLengths(); // Distances between points
for (int iter = 0; iter < iterations; iter++) {
// 1. Backward Pass
points[points.Length - 1] = target;
for (int i = points.Length - 2; i >= 0; i--) {
float dist = Vector3.Distance(points[i], points[i + 1]);
float ratio = lengths[i] / dist;
points[i] = points[i + 1] + (points[i] - points[i + 1]) * ratio;
}
// 2. Forward Pass
points[0] = rootPosition;
for (int i = 0; i < points.Length - 1; i++) {
float dist = Vector3.Distance(points[i + 1], points[i]);
float ratio = lengths[i] / dist;
points[i + 1] = points[i] + (points[i + 1] - points[i]) * ratio;
}
}
}
In VR, you don’t want the elbow to point toward the floor. We use a Pole Target (a hint point). After the IK pass, we rotate the elbow around the Shoulder-Hand axis to face the Pole Target, ensuring the arm looks “natural.”