miaoda-game-path-core
v0.3.1
Published
Engine-agnostic path-following core: waypoint polylines, Catmull-Rom splines and cubic beziers, an arc-length 'baking' engine for constant-speed travel, and a PathFollower with tangent-facing rotation and perpendicular sine sway. No rendering, no engine d
Maintainers
Readme
miaoda-game-path-core
Use this package for scripted continuous movement along waypoints, Catmull-Rom splines, or cubic Bezier curves. It bakes curve length for approximately constant-speed travel and provides tangent-facing rotation, loop/ping-pong modes, and optional sine sway.
This is path following, not pathfinding. Use grid-core to find a route around obstacles, shooter-core for free-moving bullets, and combat2d-core for hits.
Install and follow a path
pnpm add miaoda-game-path-coreimport { BakedPath, PathFollower, SplinePath } from 'miaoda-game-path-core';
const path = new SplinePath([
{ x: 900, y: 700 },
{ x: 500, y: 620 },
{ x: 220, y: 520 },
{ x: 480, y: 420 },
]);
const follower = new PathFollower(new BakedPath(path), {
speed: 260,
mode: 'clamp',
sway: { amplitude: 18, frequency: 1.2 },
});
const sample = follower.tick(dtSeconds);
moveActor(sample.pos.x, sample.pos.y);
faceActor(sample.angleDeg);
if (sample.done) beginCombatAI();speed is world units per second and tick receives seconds. Angles are degrees with 0 along +X; the renderer decides whether increasing Y appears up or down.
Choose path geometry
| Path | Use it for |
| --- | --- |
| PolylinePath | Exact straight segments and hard waypoint corners |
| SplinePath | Smooth curves that pass through authored waypoints |
| BezierPath | Explicit cubic handles for loops, hairpins, and controlled S-curves |
Raw curve parameter t is not proportional to distance. Wrap geometry in BakedPath and query by distance to avoid actors slowing on bends and accelerating on straights. Increase samplesPerSegment for tighter curves; rebuild when geometry changes.
Follower behavior
clampstops at the end and reportsdone.loopwraps to the start.pingpongreflects at both ends.swayadds perpendicular sine movement without changing the reported tangent heading.
Use seek to jump to a distance and setSpeed to change travel speed. The core returns desired transforms only; rendering, collision, pausing, and handing control to another movement system remain game-owned.
