Bullet runs into issue when collided with more then one enemy

Hey, I'm making a space invaders game & I made a bunch of different kind of bullets the player can use, but when a bullet collides with 2 enemies it gives me a bullet remove error. for (int i = Bullet.size()-1; i >= 0; i--) { bullet bu = Bullet.get(i); bu.show(); bu.move(); for (int j = Enemy.size()-1; j >= 0; j--) { enemy en = Enemy.get(j); float d = dist(bu.x,bu.y,en.x,en.y); if (d < bu.r + en.r){ Bullet.remove(i); en.life -= 1; } } }

anyone know a way to fix it so my bullet ca hit 2 enemies without an error. I think the trouble is that both enemies it collided with are trying to remove it at the same time.

Answers

Sign In or Register to comment.