My enemy doesnt look at player properly when he’s behind him. Like it’s shown on gif
But when i stay ahead of enemy he looks at me properly, but as soon as I stay behind him like it’s shown on gif he doesn’t rotate to me and starts looking at me incorectly . I’ve tried many ways to fix it, but nothing seems to work as i want. So here’s my code, I don’t know what’s wrong with it .
private void RotateToTarget()
{
Quaternion enemyRotation;
Vector3 directionTolook = (player.transform.position - transform.position);
angle = Mathf.Atan2(directionTolook.y, directionTolook.x) * Mathf.Rad2Deg;
enemyRotation = Quaternion.Euler(0f, angle, 0f);
transform.rotation = Quaternion.Slerp(transform.rotation, enemyRotation, rotationSpeed * Time.deltaTime);
}
Thanks in advance!