closer
Boid.prototype.moveCloser = function(boids, distance) {
if(boids.length < 1) return
var avgX = 0;
var avgY = 0;
for(var i = 0; i < boids.length; i++) {
var boid = boids[i];
if(boid.x == this.x && boid.y == this.y) continue;
if(this.distance(boid) > distance) continue;
avgX += (this.x - boid.x);
avgY += (this.y - boid.y);
boid = null;
}
avgX /= boids.length;
avgY /= boids.length;
distance = Math.sqrt((avgX * avgX) + (avgY * avgY)) * -1.0
if(distance == 0) return;
this.xVelocity= Math.min(this.xVelocity + (avgX / distance) * 0.15, maxVelocity)
this.yVelocity = Math.min(this.yVelocity + (avgY / distance) * 0.15, maxVelocity)
}