im trying to implement a collision method where more than one bullet can collide with loads of baddies at the same time. So far my collision works, but when i fire a few bullets i get the following error:
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:663)
at greenfoot.Actor.getOneIntersectingObject(Actor.java:912)
at bullet.collision(bullet.java:33)
at bullet.act(bullet.java:22)
at greenfoot.core.Simulation.actActor(Simulation.java:568)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:526)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
Heres my bullet class:
public class bullet extends Actor
{
public void act()
{
move(5);
collision();
}
public bullet(int direction)
{
setRotation(direction);
}
private void collision()
{
Actor baddie=getOneIntersectingObject(Baddie.class);
if(baddie !=null)
{
getWorld().removeObject(baddie);
getWorld().removeObject(this);
}
}
}
Any suggestions?
Thanks in advance!