I know there are forms telling you to set the rotation towards the player and move towards it, but with my enemy textures I need a way where they move towards the player without turning. Can anyone help?
turnTowards(/* location coordinates */); move(/* speed */); setRotation(0);
public void followHuman()
{
int dist = 1000;
Actor closest = null;
if(!getObjectsInRange(dist, Player.class).isEmpty())
{
for (Object obj: getObjectsInRange(dist, Player.class))
{
Actor Player = (Actor) obj;
move(2);
int playerDist = (int) Math.hypot(Player.getX() - getX(), Player.getY() - getY());
if (closest == null || playerDist< dist)
{
closest = Player;
dist = playerDist;
}
}
turnTowards(closest.getX(),closest.getY());
}
}