Hi everyone.
I'm working on a 2d android game with fairly simple physics. Every update all movable objects are updated
{
for(int j = i + 1; j < objects.size(); j++)
{
if(!objects.get(i).equals(objects.get(j)))
{
CheckCollisions(objects.get(i), objects.get(j));
}
}
}
But if I take out that if statement; every few updates every object in the level collides with itself (which is rather annoying).
I have single stepped through my code and I'm certain that no object ever actually adds itself to a single grid space more than once in an update. Does anyone have any ideas of what could possibly be causing this problem?
I'm working on a 2d android game with fairly simple physics. Every update all movable objects are updated
- They apply their velocity (add velocity * deltaT to position).
- They check for collisions against any walls in the level.
- Then they find which grid spaces they are in and give the physics manager a vector containing the coordinates of each space they are in.
- After updating all objects the physics manager goes through each grid space in the level and gets a vector containing all of the objects in that space which it performs the following loop on.
{
for(int j = i + 1; j < objects.size(); j++)
{
if(!objects.get(i).equals(objects.get(j)))
{
CheckCollisions(objects.get(i), objects.get(j));
}
}
}
- Then .clear() is called on the objects vector so that it is ready for next update.
But if I take out that if statement; every few updates every object in the level collides with itself (which is rather annoying).
I have single stepped through my code and I'm certain that no object ever actually adds itself to a single grid space more than once in an update. Does anyone have any ideas of what could possibly be causing this problem?