What it does
One function, fly, advances one flyer by one step. Each step you pass what the rider is doing: thrust forward or back,
a strafe, a turn and an aim pitch. Held thrust moves a cruise speed up or down, and it holds when the key is released,
with a single tap stepping it by a set amount. A strafe key slides the flyer sideways and the slide decays when
released. The turn is capped at a turn rate and the pitch at a maximum, so a fast mouse cannot spin the view.
Height takes care of itself. Looking up climbs fully below one height over the ground and fades to nothing at a soft ceiling, above which the flyer sinks. It never goes below a clearance over land or sea, so it rides up hills rather than crashing into them. Horizontal speed holds whatever the pitch, so looking down at a target does not slow the flight. The turn rate the step reports drives a bank of the camera into turns.
The flyer and its command are plain numbers, so a snapshot is just those numbers, and the model asks of the ground only its height at a point and how coordinates wrap. That makes it fit a wrapping world, a terrain field or a flat plane alike. It is pure, deterministic and draws nothing.
Features
- Fly where you look — yaw and pitch steer the flight, and
lookVectorgives the direction for aiming shots. - A cruise that holds — held keys move the cruise speed, a tap steps it,
stopzeroes it, and a reverse speed is a share of the top speed. - Slides that decay — strafing moves at a slide speed and eases off at a decay rate when released.
- A soft ceiling and terrain following — climbing fades out towards the ceiling, the flyer sinks above it and rides at a clearance over hills and sea.
- Wrapping worlds — positions fold through the ground's own wrap, so a torus world has no edge.
- Camera numbers — the rider's eye height, the share of the aim pitch the camera shows and a bank per unit of turn, plus a speed scale for boosts.
Good for
- Flying-carpet and wizard battles in the style of Magic Carpet, where the player and every rival fly by the same model.
- Exploration flyers over open landscape, such as a glider, a broom or a spirit, where crashing would only get in the way.
- Drone and camera flights that should hug the terrain at a steady height.
- Arena shooters over terrain, where the player strafes and aims while the cruise carries them on.
Make it yours
A FlightDef holds every number, in world units and seconds: top speed, how fast held keys move the cruise, the tap
step, reverse speed, strafe speed and decay, turn rate and pitch limit, the full-climb height, the ceiling, the sink
rate and the clearance, plus the eye height, view pitch share, bank, and boost multipliers for a held boost and after
it. The ground is any object with groundAt(x, z) and wrap(v).
Two quite different uses: a quick, agile carpet with a fast turn rate and a low ceiling, skimming a wrapping island world in a duel; and a slow, stately glider over a flat terrain field, with a gentle turn, a high ceiling and a long slide decay, for a calm sightseeing game.
A quick look
A flyer stepped by the keys and mouse, with the camera following its yaw, pitch and bank:
const { fly, lookVector } = game.cruiseFlight;
const f = { x: 0, y: 40, z: 0, vx: 0, vy: 0, vz: 0, yaw: 0, pitch: 0 }; // a Flyer
const c = { cruise: 0, slide: 0, turnRate: 0 }; // its FlightCommand
fly(f, c, { thrust: keys.up ? 1 : 0, strafe, turn: mouseDx * 0.003, pitch: aim }, def, land, dt);
camera.yaw = f.yaw; camera.pitch = f.pitch * def.viewPitch; camera.roll = c.turnRate * def.bank;
lookVector(f.yaw, f.pitch); // where shots go
Works with
torus-land— a wrapping land that answers both questions the model asks of the ground.terrain-3d— a terrain field, with an identity wrap.mana-conquest— a flying-carpet conquest game that flies the player and every rival by this model.jet-combat— for aircraft with banking and energy.heli-assault— for hovering gunships.rail-route— for a flight that flies itself.
Good to know
- There is no physics: no momentum beyond the slide, no stall and no gravity below the ceiling.
- The only collision is with the ground, through the clearance; obstacles above it are your game's to handle.
- One call moves one flyer: formation, avoidance and AI steering are the caller's.






