Make an object ignore itself?
in
Programming Questions
•
2 years ago
Hi, the code below part of a sketch I'm working on with an array of objects that check their distance between themselves and the other objects in that array. Does anyone know how I can make the object ignore itself, or even just think of a better way of doing this. The idea is that the object will be aware of it's distance from other objects in the array and eventually "make decisions" based on it's range from them...
I think I'm correct in assuming the reason it isn't working at the moment and always returns true is because at some point it's comparing the distance between itself and itself, I want it to ignore it's own slot in the array.
Any pointers much appreciated.
D.
boolean collision(Marker m) {
float distance = dist(getLocX(), getLocY(), m.getLocX(), m.getLocY());
if (distance < radius + m.radius) {
return true;
} else {
float distance = dist(getLocX(), getLocY(), m.getLocX(), m.getLocY());
if (distance < radius + m.radius) {
return true;
} else {
return false;
}
}
void listen() {
}
}
void listen() {
for (int i = 0; i < numMarkers; i++) {
if ( collision (markers[i])) {
//do something
}
}
}
1
