Okay so i havebeen rotating my enemy to face the player using
float targetrotation = Math.Atan2(playerpos-enemypos);
enemy.rotation = targetrotation; (<this line of code i want to change)
This simple method has worked fine so far for getting the enemy to look at the player's position. However i decided to add some extra code to get the enemy to gradually rotate towards the player using this method:
if(enemy.rotation < targetrotation)
{
enemy.rotation++;
}
if(enemy.rotation > targetrotation)
{
enemy.rotation--;
}
Now the problem i am having is that when the player moves for example from 360 degree target to 1 degree then the enemy rotates the long way round to move to the 1 degree instead of simply adding 1 degree. Any help on how to correct this problem would be welcomed. I have a picture below: