1. Check out our companion app, Forums for Android! Download from Google Play

Java Vectors

Discussion in 'Application Development' started by Kailas, Sep 15, 2010.

  1. Kailas

    Kailas Member
    Thread Starter

    Aug 25, 2010
    Hi everyone.

    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 i = 0; i < objects.size(); i++)
    for(int j = i + 1; j < objects.size(); j++)
    CheckCollisions(objects.get(i), objects.get(j));

    • Then .clear() is called on the objects vector so that it is ready for next update.
    My problem is that the if statement shouldn't be necessary because there is no way for an object to add itself to the same space multiple times in the same update (and the vector gets cleared after every 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?


Share This Page