What it does
A route is a graph of legs. Each leg is a straight run or a smooth spline through points, in world space or relative to where the last leg ended, and carries keys along its length for speed, roll, yaw, pitch and a look-at target. The frames along the path are rotation-minimising, so a loop or a climb never flips the camera. A leg can hold the rider until a predicate is true, a group is cleared or a time passes, and can end in a branch chosen first, at random, by your rules or by the player shooting a sign.
The rider can simply be carried, or given a pilot offset inside the leg's walls, steered by position or velocity, banking as it turns, or following the crosshair. The view can turn toward the crosshair or track a point at any angle. Cues on each leg spawn targets by distance or time, once or repeatedly, and targets live in world space, on the route or in rider space, where a formation keeps its place on screen while the route banks.
Targets carry everything a rail shooter fights: sphere and box hit regions with destructible parts and armour, depth windows, pop-up exposure for light-gun games, friendly hostages, firing schedules, lifetimes, solid bodies that hurt on collision and reports when the rider flies through them. Enemy projectiles home, lead their aim, close exponentially or drift with per-axis pulls, and some can be shot down. The gun resolves instant rays, lasting beams that follow the crosshair, or swept bolts that cannot tunnel. A shield counter takes the damage, with immunity windows after a hit.
Features
- Authored routes — straight legs and Catmull-Rom splines, keyed speed, roll, yaw, pitch and look-at, without frame flips on loops.
- Holds and branches — stops until a predicate, a cleared group or a time, and branches by order, chance, rules or input.
- A pilot inside the route — position or velocity steering within walls, banking, and a view that follows the crosshair or tracks a point.
- Spawn cues — by leg distance or time, repeating, gated, with spawn specs or functions.
- Targets at depth — world, route or rider space; static, velocity, keyframed or behaviour motion; hit regions, parts, depth windows and exposure.
- Enemy fire — schedules with windows and chances, and projectiles that home, lead, close or drift, some shootable and some harmless outside the crosshair's reach.
- A gun — rays, delayed or lasting beams that follow the aim, or swept bolts, with cooldown, damage and a pick call for a second weapon.
- Shields — start and maximum, damage events, and immunity after a hit.
- Projection helpers — the camera pose, screen-to-aim and back, aim rays and target frames, matching the vector pack's camera space.
- Deterministic — fixed steps, seeded randomness, plain-data state, and snapshot and restore.
Good for
- Colour-vector cockpit shooters in the style of the 1983 Star Wars arcade game, with a trench run and shootable
fireballs, through
wire-cockpit. - Polygon space rail shooters in the style of Starblade, with banking splines and homing missiles, through
polygon-rail. - Light-gun games in the style of Time Crisis or House of the Dead, with stops, pop-up enemies and hostages,
through
cover-shooter. - Rollercoaster shooting galleries, a looping spline with roll keys and pop-up targets.
- Canyon flights with a steerable pilot and solid rock arches to dodge.
- Your own rail shooter rules, built directly on the route, targets and gun.
Make it yours
Everything is the rail definition passed to createRail: the camera and its aim limits, the legs and their keys,
pilots, looks, cues, holds and branches, the rider's radius and immunity, the target kinds and their behaviours, the
projectile kinds, the gun, the shields, resource limits and the seed. setScale adjusts speed, fire rate and
projectile speed for difficulty.
The same API runs materially different games. A trench run is a long straight leg with a velocity-controlled pilot that follows the crosshair, turrets firing drifting shots and a lasting beam gun. A rolling space battle is a relative spline with roll and look-at keys, multi-hit enemies and homing missiles. A light-gun street is short legs that hold until each group is cleared, pop-up targets, a hostage that must not be shot, and a branch picked by shooting a sign.
A quick look
A trench leg with a steerable pilot, a turret kind and a lasting beam, stepped from the crosshair:
const rail = game.railRoute.createRail({
camera: { fov: 1.0, aspect: 4 / 3 },
legs: [{ id: "run", phase: "trench", length: 300000, speed: 11000, pilot: { x: [-511, 511], y: [-3583, -257], rate: [0.44, 0.94], relative: true, mode: "velocity", follow: "aim" } }],
kinds: [{ id: "turret", radius: 300, points: 100, fire: { projectile: "shot", every: 2, window: { far: 24000 } } }],
projectiles: [{ id: "shot", speed: 0, gain: { x: 0.9, y: 0.9, z: 0.23 }, reach: 1040, needsAim: true, points: 33 }],
gun: { mode: "ray", duration: 0.4, follow: true, auto: false, replace: true },
shields: { start: 6 }, seed: 1,
});
rail.step({ aim: rail.screenToAim(px, py, view), fire: trigger });
for (const e of rail.drain()) { /* leg-enter, hold, spawn, hit, destroyed, fired, projectile-hit, damage ... */ }
const pose = rail.pose(); // eye, forward, up, right, roll, velocity
Works with
wire-cockpit— colour-vector cockpit rules, one rail per wave.polygon-rail— polygon gunner rules with missions, forks and bosses.cover-shooterandlight-gun— ammunition and cover on top of the gun, holds and exposure.vector-wire— projects vector models in the same camera space.world-3d— a 3D camera set from the route's pose, with meshes placed at target frames.scaled-depth— for sprite-scaling shooters, andpseudo-roadfor a pseudo-3D road.
Good to know
- There is no occlusion: a ray hits the nearest target region, and cover that blocks shots is a rules concern.
- One rider and one gun per rail; a second weapon is a rules action using
pick. - By default at most 512 targets and 512 projectiles are live, and spawns past that are refused with an event.
- Snapshots hold state only, so restore into a rail built from the same definition.
- A projectile's hit test is against the rider's sphere or its reach, not against a model.






