Hey,
I am trying to get my enemies bounce of the wall to the opposite direction once it touches the side but i keep getting an error saying
"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."
My code is this:
private int delaytime = 150;
public void act()
{
if(getX() == 1)
{
setRotation(0);
}
if(getX() == getWorld().getWidth()-1)
{
setRotation(180);
}
if(Greenfoot.getRandomNumber(10)%7==0)
{
if(delaytime==0)
{
delaytime=150;
getWorld().addObject(new BadLaser(), getX(), getY());
}
delaytime--;
}
}