I am trying to make an actor follow the main player of my game by moving left when the player is in range but on the left side, then right when the player is on the right side and in range. Im using a separate counter (which works fine) to make the the enemy follow the player in different directions. When the player reached the middle of the range (so on top of the enemy) it should switch to the other movement pattern. Im confused as how to find the center of the radius. objects.size >0 detects if the player is in the range at all but i am not sure what to do to detect the center of the range. Any help is appreciated thank you!
public void patternSet()
{
Actor Player;
List <Player> objects = getObjectsInRange (200, Player.class);
if(turnAmount == 0)
{
if ( objects.size() >0 && objects.size() < 100)
{
setLocation(getX() - 1 ,getY() );
}
else
{
turnCount(1);
}
}
if(turnAmount == 1)
{
if ( objects.size() >0 && objects.size() <1)
{
setLocation(getX() + 1 ,getY() );
}
else
{
turnCount(-1);
}
}
}
