【发布时间】:2021-09-14 15:20:33
【问题描述】:
我在 p5js 中的基因 3D boid 不断逃离它们的边界框。我一定做得不对,可以使用一些帮助。这是live sketch。
这是边界框代码:
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); //-++
}
我们将不胜感激。
【问题讨论】:
-
在一个物体超过一个边界条件后确定新的期望速度时,为什么要使用 maxspeed 这么多?您能否描述一下当您的 boid 到达边界框边缘时您希望看到的行为?
-
您知道,console.log 函数会大大减慢您的程序。在您的最终版本中,您必须删除它。不确定您是否知道,但如果您知道,您可以忽略此评论。
标签: 3d p5.js bounding-box boids artificial-life