How could i get one acter run away from another
getActorsInRange(num, Actor.class);
if (getActorsInRange(num, Chasing.class).size() > 0)
{
runAway(); //This method will only get called if the size of the Chasing actors in range is greater than 0
}
...turnTowards(x,y); turn(amount); setRotation(rot); getRotation(); move(amount);
//Make sure that the size of getActorsInRange is greater than 0! Actor act = getActorsInRange(num, Chasing.class).get(0);
turnTowards(act.getX(), act.getY());
turn(180); //or turn(-180) both do the same OR setRotation(getRotation()+180); //or getRotation()-180)
move(amount);
public void act()
{
move(9);
if (atWorldEdge())
{
turn(68);
}
if (Greenfoot.getRandomNumber(100) < 20)
{
turn( Greenfoot.getRandomNumber(100)-50 );
}
if (getActorsInRange(1, Frog.class).size() > 0)
{
runAway();
}
} if (getObjectsInRange(num, Hero.class).isEmpty())
{
// normal random movement
}
else
{
// get object reference to retrieve location from
// use location in 'turnTowards' method
// move
}