#Boids simulation - spawning point looks weird

2 messages · Page 1 of 1 (latest)

mystic cobalt
#

Hi everyone,

I've been working on a boids simulation. But I have a little weird problem, when it comes to edge/border behavior.
I wanted them to appear back at 0 if they hit the border, so that they just seamlessly fly in this specific 3D area.
But it looks like as they would spawn at (0, 0, 0). At least there is one boid that looks like it would clone itself multiple times again and again.

Does anyone have a clue why this happens? I tried a lot on the edge()-function, but I can't think of what the problem is.

!! Also if I try other conditions for the if-statements, there are other weird things happening around the (0, 0, 0).

Thanks in advance!

Specific code line:

The boundaries are set to:

        this.xBoundaries = 2000;
        this.yBoundaries = 2000;
        this.zBoundaries = 2000; 

```

The edges:
```
edges(){

       if (this.position.x > this.xBoundaries){
            this.position.x = 0;
        } else if(this.position.x < 0){
            this.position.x = this.xBoundaries;
        }

        if (this.position.y > this.yBoundaries){
            this.position.y = 0;
        } else if(this.position.y < 0){
            this.position.y = this.yBoundaries;
        }

        if (this.position.z > this.zBoundaries){
            this.position.z = 0;
        } else if(this.position.z < 0){
            this.position.z = this.zBoundaries;
        } 
}
```

Calling the edges(): 
```
function animate() {
    requestAnimationFrame(animate);

    for (let boid of flock) {
        boid.edges();
        boid.flock(flock);
        boid.update();
        boid.show();
    }

    controls.update();
    renderer.render(scene, camera);
}

```
shut sentinel
#

I think you may have a hard time getting people to sift through 17 megs of unknown content to try and figure out what might be going on here. I'd suggest extracting out the behavioral code specifically and offering that up.