We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys. So I created objects that move randomly around. I noticed that when they collide, they "become one" and move together on the same path. Any idea why this is happening? Or is it just coincidence?
//sketch.js
var count = 50;
var org = [];
function setup() {
createCanvas(500,500);
for(var i = 0; i < count; i++){
org[i] = new Organism();
}
}
function draw() {
background(255);
for(var i = 0; i < org.length; i++){
org[i].move();
org[i].display();
}
}
function Organism(){
this.size = random(15, 30);
this.x = random(0, 500);
this.y = random(0, 500);
this.move = function(){
this.x += (noise(this.x*0.034, this.y*0.034, frameCount*.021) - .5) * 15;
this.y += (noise(frameCount*.021, this.x*0.034, this.y*0.034) - .5) * 15;
};
this.display = function(){
ellipse(this.x, this.y, this.size, this.size);
};
}
Answers
Perhaps see this recent related discussion of problems with collision detection: https://forum.processing.org/two/discussion/20944/simple-rect-collision-from-array#latest
Edit: I haven't tested it, but actually it looks like your Organism.move() function might be deterministic based on location...? So two objects in the same place would always move in the same way.
Yes, read up about noise(). it is not random.
There is no collision detection on your code so it can't be that.