npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

miaoda-game-steering2d-core

v0.1.1

Published

Deterministic engine-independent 2D steering: seek, wander, host-queried obstacle avoidance, exact pursuit/interception, flocking, and bounded composition.

Readme

miaoda-game-steering2d-core

Deterministic, engine-independent steering for autonomous actors in continuous 2D space. It provides seek, flee, arrive, exact constant-velocity pursuit/interception, evade, stateful wander, host-queried obstacle avoidance, separation, alignment, cohesion, and bounded steering composition.

Use it for top-down action and shooting enemies, flying tower-defense units, RTS squads, traffic, flocking, homing enemies, and moving bosses. It is not grid pathfinding: navigation chooses a route, while steering chooses the desired velocity and acceleration for the next simulation step.

pnpm add miaoda-game-steering2d-core
const chase = pursuit(enemy, { position: player.pos, velocity: player.velocity }, {
  maxPrediction: 2,
});

const flockAcceleration = combineWeighted([
  { acceleration: separation(enemy, neighbors, { radius: 36 }).acceleration, weight: 1.5 },
  { acceleration: alignment(enemy, neighbors, { radius: 96 }).acceleration, weight: 0.7 },
  { acceleration: cohesion(enemy, neighbors, { radius: 96 }).acceleration, weight: 0.5 },
], enemy.maxAcceleration);

// The host owns and snapshots both rng and wanderState.
const roaming = wander(enemy, wanderState, () => rng.next(), {
  circleDistance: 24,
  circleRadius: 12,
  maxAngleChange: Math.PI / 8,
});
wanderState = roaming.state;

// `castActor` belongs in the Phaser/Cocos/kinematic adapter. It returns data only.
const avoiding = avoidObstacles(enemy, roaming.desiredVelocity, castActor, {
  lookAhead: 48,
  radius: 8,
  sidePreference: 1,
});

The package only calculates desiredVelocity and bounded acceleration. Your fixed-step loop integrates velocity; miaoda-game-kinematic2d-core or engine physics owns position and collision response. A behavior tree or FSM decides when to chase, flee, or flock. Neighbor arrays can come from miaoda-game-targeting2d-core without a package-level dependency.

wander never calls Math.random: it consumes exactly one value from the supplied random source and returns the angle state needed for deterministic continuation. Persist that angle beside the caller-owned RNG snapshot.

avoidObstacles emits a read-only circle/capsule-cast request through ObstacleQuery, validates the nearest hit, and calculates a deflected desired velocity. The adapter may implement that query with Phaser ray/shape tests, Cocos physics queries, kinematic2d-core, a tile map, or a custom navigation world. The function never writes a body velocity, integrates position, or resolves penetration, so engine physics remains the sole movement and collision authority.

solveInterceptTime solves the constant-velocity interception quadratic and returns the earliest non-negative time. It returns null when interception is impossible or beyond maxPrediction; pursuit and evade then use the target's current position. Flocking excludes self by stable id, and coincident pairs receive deterministic opposite separation directions.

Vector helpers require finite inputs. normalize preserves direction for subnormal and extreme finite vectors and returns {x:0,y:0} only for the zero vector. limitMagnitude uses the same scale-stable direction. Arithmetic that would turn finite operands into an unrepresentable Infinity/NaN result throws RangeError.