我在 p5js 中的基因 3D boid 不断逃离它们的边界框。我一定做得不对,可以使用一些帮助。这是一个现场草图。
这是边界框代码:
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); //-++
}
协助将不胜感激。