Skip to content

Commit

Permalink
fix avg stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mallsoft committed Oct 14, 2024
1 parent 9727a0e commit d39d790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/lib/components/visuals/Bees/bee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export class Bee {
else if (this.pos.y < 0) this.pos.y = window.innerHeight;
}

private hunt(flock: Bee[]) {
private hunt(flock: Bee[], factor = 1) {
if (this.hunting) {
this.turn(this.hunting.pos, 0.09 * Math.random());
this.turn(this.hunting.pos, factor);

if (this.pos.dist(this.hunting.pos) < 100) {
this.hunting = null;
}
} else if (Math.random() < 0.02) {
} else if (Math.random() < 0.05) {
this.randSpeed();
this.hunting = flock[Math.floor(Math.random() * flock.length)];
}
Expand All @@ -95,9 +95,13 @@ export class Bee {

this.wrap();

this.hunt(flock);
this.hunt(flock, 0.05);

this.turn(avgHeading, 0.08).turn(avgCenter, 0.08);
this.dir.add(avgHeading, 0.05);

this.turn(avgCenter, 0.02);

// randomize to avoid circular chase?

this.dir.normalize();

Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/visuals/Bees/flock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const flockStep = () => {
avgHeading.add(b.dir);
avgCenter.add(b.pos);
}
// avgHeading.mult(1 / flock.length);
// avgCenter.mult(1 / flock.length);
avgHeading.mult(1 / flock.length);
avgCenter.mult(1 / flock.length);

for (const b of flock) {
b.step({ avgHeading, avgCenter, flock });
Expand Down

0 comments on commit d39d790

Please sign in to comment.