i think i managed to implement your approach, with addedToWorld now. not sure if this is how you intended
so sorry for all the posts, i just really want this to work
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class NPC here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class FloatingSkull extends Actor
{
PC player;
private int rotation = Greenfoot.getRandomNumber(360);
private int speed = 1;
private boolean aggro = false;
private int[] roamLimit = new int[4];
private int roamLimitRange = 50;
public void act(){
movementAI();//track the player as soon as they enter a certain AOE, increase speed
}
protected void addedToWorld(MyWorld World){
roamLimit[0] = getX()+roamLimitRange;
roamLimit[1] = getX()-roamLimitRange;
roamLimit[2] = getY()+roamLimitRange;
roamLimit[3] = getY()-roamLimitRange;
}
public FloatingSkull(PC player){
this.player = player;
}
public void movementAI(){
if(getObjectsInRange(200, PC.class).isEmpty() && aggro == false){
rotation += 15-Greenfoot.getRandomNumber(31); // (-15, 15) degree change in direction
setRotation(rotation);
move(speed*2);
setRotation(0);
if(getX() < roamLimit[0] || getX() > roamLimit[1] || getY() < roamLimit[2] || getY() > roamLimit[3]){
move(speed*(-1));
}
}
if(!getObjectsInRange(150, PC.class).isEmpty()){
move(speed*0);
}
else{
turnTowards(player.getX(), player.getY());
move(speed);
setRotation(0);
}
if(!getObjectsInRange(200, PC.class).isEmpty()){
aggro = true;
}
}
}
