What it does
A walker owns a position on a curve from the geometry pack: a line, a quadratic or cubic bezier, a spline, an arc, a
spiral, a sine, zigzag or square wave, a path of segments laid end to end, or the outline of any shape. The curve is
baked by arc length when the walker is made, so the object moves at the same speed everywhere, where moving by a
bezier's own parameter would race along the straights and crawl round the bends.
game.path.follow(h, shape, opts) drives an object along the curve every step, before physics, and returns the
walker. It belongs to the scene, so it is cleaned up when the scene ends, and a second follow on the same object
replaces the first. game.path.walker(shape, opts) gives a headless walker instead, which you update yourself and
read x, y and angle from, for a camera, a spawn point or anything that is not an object.
At the end a walker can stop, wrap to the start or turn back. An ease shapes each pass, so a platform can slow into
each end. at starts it part-way along, so a line of enemies can share one curve and be spaced along it, and
relative lays the curve out from where the object is standing. path.lap and path.end signals tell the game when
a pass completes.
Features
- Any geometry curve — lines, beziers, splines, arcs, spirals, waves, paths and shape outlines.
- Even speed — curves baked by arc length, with a sample count you can raise for long or wiggly routes.
- Speed or duration — units per second, or seconds for the whole curve.
- Loop modes — stop, loop or yoyo, with laps counted and the return leg reported.
- Easing — any named easing or your own function over each pass.
- Start offsets and relative curves —
atfor spacing,relativefor routes laid from the object. - Face the direction of travel —
align, with an offset in degrees for art that points another way. - Control — pause, set
tto jump, changespeedlive,reset, andstopan object. - Signals —
path.lapandpath.endfor followed objects.
Good for
- Shoot-'em-ups, with enemy waves that swoop in on curves, in the style of Galaga, or weave along a sine wave.
- Platformers, with moving platforms that ease back and forth or circle a loop.
- Boss fights, with a boss spiralling out from the centre of the arena.
- Camera rides and attract modes, with a headless walker on a spline.
- Tower defence, with creeps following a fixed winding road.
- Projectiles on arcs, such as lobbed bombs on a set curve.
Make it yours
Each walker takes its own speed or duration, loop mode, ease, start point, relative mode, alignment and offset, sample
count and whether it starts paused. The curve is plain data, so a wave of enemies can share one shape with different
at values, and a level can store its routes as shapes.
Two different uses: a shooter where twelve enemies follow one cubic bezier into the screen with align on, each
started a little further along; and a platformer where a lift rides a straight line for two seconds each way with
loop: 'yoyo' and easeInOutSine, slowing at each floor.
A quick look
An enemy on a wave, a platform that yoyos, and a free walker on a bezier:
game.path.follow(enemy, { kind: 'wave', x1: 700, y1: 80, x2: -60, y2: 80, amplitude: 40, cycles: 3 }, { speed: 160, align: true });
game.path.follow(platform, { kind: 'line', x1: 100, y1: 200, x2: 300, y2: 200 }, { duration: 2, loop: 'yoyo', ease: 'easeInOutSine' });
game.path.follow(boss, { kind: 'spiral', x: 0, y: 0, r1: 0, r2: 120, turns: 3 }, { speed: 90, relative: true });
const free = game.path.walker({ kind: 'cubic', x1: 0, y1: 0, c1x: 50, c1y: -80, c2x: 150, c2y: -80, x2: 200, y2: 0 }, { speed: 100 });
free.update(dt); free.x; free.y; free.angle;
Works with
geometry— the curves and shapes every route is made from.path-notation— routes authored as chained segments in data, such as a wave plan.path-3d— 3D curves with frames, for a coaster or a camera rail.tween— for point-to-point moves that are not a route.particles-2d— to emit along the same shape the route follows.
Good to know
- With an ease,
speedis the average over a pass;durationis exact. followsets the object's position, and its rotation withalign, every step, so physics on the same object will fight it. Use one or the other.- Baking samples the curve once, 128 points by default: raise
samplesfor a long or wiggly route. - It is 2D only; 3D routes are
path-3d.






