Catmull-Rom Splines
Bézier curves are great when an artist adjusts handles, but for gameplay you often have a list of waypoints that the path must pass through: a patrol route, a camera rail, a racing line. A Catmull-Rom spline is a smooth curve that goes through every point, with the tangents computed automatically from the neighbors. No handles to place.
The formula
Each segment between P1 and P2 uses the points on either side, P0 and P3, to choose its tangents: the tangent at P1 is parallel to P2 - P0. For the standard (uniform) version:
C(t) = 0.5 * ( 2 P1
+ (P2 - P0) t
+ (2 P0 - 5 P1 + 4 P2 - P3) t²
+ (3 P1 - P0 - 3 P2 + P3) t³ ) t from 0 (at P1) to 1 (at P2)#include <iostream>
#include <iomanip>
#include <vector>
struct Vec2 { double x, y; };
Vec2 catmullRom(Vec2 p0, Vec2 p1, Vec2 p2, Vec2 p3, double t) {
double t2 = t * t, t3 = t2 * t;
auto f = [&](double a, double b, double c, double d) {
return 0.5 * (2 * b + (c - a) * t + (2 * a - 5 * b + 4 * c - d) * t2 + (3 * b - a - 3 * c + d) * t3);
};
return {f(p0.x, p1.x, p2.x, p3.x), f(p0.y, p1.y, p2.y, p3.y)};
}
int main() {
std::cout << std::fixed << std::setprecision(3);
std::vector<Vec2> wp = {{0, 0}, {2, 3}, {5, 3}, {7, 0}, {10, 1}};
// Segments run between wp[1]..wp[2] and wp[2]..wp[3]; the end points only steer.
for (int seg = 1; seg + 2 < (int)wp.size(); seg++) {
for (int i = 0; i <= 4; i++) {
double t = i / 4.0;
Vec2 p = catmullRom(wp[seg - 1], wp[seg], wp[seg + 1], wp[seg + 2], t);
std::cout << "segment " << seg << " t=" << t << ": (" << p.x << ", " << p.y << ")\n";
}
}
}segment 1 t=0.000: (2.000, 3.000)
segment 1 t=0.250: (2.703, 3.281)
segment 1 t=0.500: (3.500, 3.375)
segment 1 t=0.750: (4.297, 3.281)
segment 1 t=1.000: (5.000, 3.000)
segment 2 t=0.000: (5.000, 3.000)
segment 2 t=0.250: (5.547, 2.367)
segment 2 t=0.500: (6.000, 1.438)
segment 2 t=0.750: (6.453, 0.539)
segment 2 t=1.000: (7.000, 0.000)
At t = 0 and t = 1 each segment lands exactly on its waypoints, and neighboring segments share tangents at the joins, so the path is smooth.
Covering the end points
With n waypoints you only get n - 3 segments: the first and last points just steer. To make the path start at the first waypoint and end at the last, add a phantom point at each end, usually by extrapolating: phantomStart = 2 * P0 - P1. For a closed loop (a patrol circuit), wrap the indices around with modulo instead.
#include <iostream>
#include <iomanip>
#include <vector>
struct Vec2 { double x, y; };
Vec2 catmullRom(Vec2 p0, Vec2 p1, Vec2 p2, Vec2 p3, double t) {
double t2 = t * t, t3 = t2 * t;
auto f = [&](double a, double b, double c, double d) {
return 0.5 * (2 * b + (c - a) * t + (2 * a - 5 * b + 4 * c - d) * t2 + (3 * b - a - 3 * c + d) * t3);
};
return {f(p0.x, p1.x, p2.x, p3.x), f(p0.y, p1.y, p2.y, p3.y)};
}
// Sample a closed loop through all waypoints; u runs from 0 to the number of points.
Vec2 loopPoint(const std::vector<Vec2>& w, double u) {
int n = (int)w.size();
int i = (int)u % n;
double t = u - (int)u;
return catmullRom(w[(i - 1 + n) % n], w[i], w[(i + 1) % n], w[(i + 2) % n], t);
}
int main() {
std::cout << std::fixed << std::setprecision(2);
std::vector<Vec2> patrol = {{0, 0}, {4, 0}, {4, 4}, {0, 4}}; // a square route
for (int k = 0; k < 8; k++) {
double u = k * 0.5;
Vec2 p = loopPoint(patrol, u);
std::cout << "u=" << u << ": (" << p.x << ", " << p.y << ")\n";
}
}u=0.00: (0.00, 0.00)
u=0.50: (2.00, -0.50)
u=1.00: (4.00, 0.00)
u=1.50: (4.50, 2.00)
u=2.00: (4.00, 4.00)
u=2.50: (2.00, 4.50)
u=3.00: (0.00, 4.00)
u=3.50: (-0.50, 2.00)
The guard passes through each corner of the square and rounds it smoothly, bulging a little outward between corners (at u = 0.5 the path is at y = -0.5). That overshoot is a property of the spline: it is a smooth curve, not a straight line with rounded corners.
Uniform, centripetal and chordal
The formula above is the uniform variant: every segment gets the same t range, whatever its length. When waypoints are unevenly spaced, uniform Catmull-Rom can overshoot wildly or even form little loops near close points. The centripetal variant (parameter alpha = 0.5) spaces t by the square root of the distance between points and is guaranteed never to form cusps or self-intersections within a segment. Most engine spline tools default to it or offer it:
| Tool | Catmull-Rom support |
|---|---|
| Unity Splines package | TangentMode.AutoSmooth (Catmull-Rom-style auto tangents) |
Unreal USplineComponent |
CurveAuto points compute tangents from neighbors automatically |
Godot Curve3D |
Bézier with handles; Curve3D has no auto Catmull-Rom, so compute handles from neighbors |
| Three.js | CatmullRomCurve3(points, closed, 'centripetal') |
Splines in practice
- Camera rails: place 6–10 waypoints along a cutscene path, sample with an arc-length table (Bézier lesson) for constant speed, and slerp the camera rotation separately.
- Racing AI: a spline through the ideal racing line; each car steers toward a point a little ahead of its closest point on the spline.
- Projectile arcs and trails: keep the last N positions and draw a Catmull-Rom through them for smooth trails at low sample rates.
Tip: A Catmull-Rom segment can be converted to a cubic Bézier exactly: the control points are
P1,P1 + (P2 - P0) / 6,P2 - (P3 - P1) / 6,P2. That lets you author paths as waypoints and render them with any Bézier tool or SVG path.
Test yourself
What is the main difference between Catmull-Rom splines and Bézier curves for game paths?
- Catmull-Rom curves pass through every waypoint
- Catmull-Rom curves are always straight
- Bézier curves pass through every control point
- Catmull-Rom needs four times more points
The tangent of a uniform Catmull-Rom spline at waypoint P1 is parallel to what?
- P1 - P0
- P2 - P0
- P3 - P2
- The world up
Which variant avoids cusps and loops with unevenly spaced waypoints?
- Uniform
- Centripetal (alpha = 0.5)
- Linear
- Quadratic