We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
If you want to remove both targets then you should remove the bullet after it has checked all the targets.
Kf
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9NGjx94YMTtlu
http://Studio.ProcessingTogether.com/sp/pad/export/ro.9K-kjhuONcJDZ