@thi.ng/boids
Version:
n-dimensional boids simulation with modular behavior system
19 lines (18 loc) • 547 B
JavaScript
import { __ensureFn } from "../internal/ensure.js";
const dynamicTarget = (target, radius = Infinity, weight = 1) => {
let currTarget;
const $radius = __ensureFn(radius);
const force = [];
return {
weight: __ensureFn(weight),
update: (boid) => {
currTarget = target(boid) || currTarget;
if (!currTarget) return boid.api.ZERO;
const r = $radius(boid);
return boid.api.distSq(currTarget, boid.pos.curr) < r * r ? boid.steerTowards(currTarget, force) : boid.api.ZERO;
}
};
};
export {
dynamicTarget
};