From 2df948ca0509b8bf58d1b7bc3a5ce0840132edd1 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Tue, 13 Oct 2020 22:18:17 +0100 Subject: Fully sort detection of boids colliding --- resources/js/boid.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'resources/js/boid.js') diff --git a/resources/js/boid.js b/resources/js/boid.js index 85793ff..a15022a 100644 --- a/resources/js/boid.js +++ b/resources/js/boid.js @@ -70,7 +70,7 @@ class Boid { let rayAngle = tweakAngle + this.direction + rays[i]; // Check against all other boids - if (i == 0 && this.detectBoids(rayAngle, boids)) { + if (this.detectBoids(rayAngle, boids)) { continue; } @@ -81,8 +81,9 @@ class Boid { return rayAngle; } - console.log(this.x, this.y); + console.log('cannot find suitable ray'); + return false; } detectBoids(direction, boids) { @@ -112,10 +113,12 @@ class Boid { if (intersect) { console.log('boids intersect detected'); } + + return intersect; } boidsIntersect(boid) { - this.twoCirclesIntersect(this.radius, boid.radius, this.x, boid.x, this.y, boid.y); + return this.twoCirclesIntersect(this.radius, boid.radius, this.x, boid.x, this.y, boid.y); } twoCirclesIntersect(r1, r2, x1, x2, y1, y2) { -- cgit v1.2.3