Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function seek(target, boid) {
// A vector pointing from the boid location to the target
const desired = Vector.sub(target, boid.position);
// Normalize and scale to maximum speed
desired.normalize();
desired.mult(boid.maxSpeed);
// Steer = Desired - Velocity
const steer = Vector.sub(desired, boid.velocity);
// Limit to maximum steering force
steer.limit(boid.maxForce);
return steer;
}
function seek(target, boid) {
// A vector pointing from the boid location to the target
const desired = Vector.sub(target, boid.position);
// Normalize and scale to maximum speed
desired.normalize();
desired.mult(boid.maxSpeed);
// Steer = Desired - Velocity
const steer = Vector.sub(desired, boid.velocity);
// Limit to maximum steering force
steer.limit(boid.maxForce);
return steer;
}
([count, direction], otherBoid) => {
const d = boid.position.dist(otherBoid.position);
if (d > 0 && d < CONFIG.desiredSeparation) {
// Calculate vector pointing away from neighbour
const diff = Vector.sub(boid.position, otherBoid.position)
.normalize()
.div(d); // Weight by distance
return [count + 1, direction.add(diff)];
}
return [count, direction];
},
[0, new Vector(0, 0)],