My genetic 3D boids in p5js keep escaping their bounding box. I must not be doing it correctly, and could use some help. Here is a live sketch.
Here is the bounding box code:
if (this.position.x < d) {
desired = createVector(this.maxspeed, this.velocity.y, this.maxspeed);
} else if (this.position.x > widthZone - d) {
desired = createVector(-this.maxspeed, this.velocity.y, this.maxspeed); //-+-
}
if (this.position.y < d) {
desired = createVector(this.velocity.x, this.maxspeed, this.maxspeed);
} else if (this.position.y > heightZone - d) {
desired = createVector(this.velocity.x, -this.maxspeed, this.maxspeed); //+--
}
if (this.position.z < d) {
desired = createVector(this.maxspeed, this.maxspeed, this.velocity.z);
} else if (this.position.z > depth - d) {
desired = createVector(this.maxspeed, this.maxspeed, -this.velocity.z); //-++
}
An assist would be most appreciated.