Hello, I'm developing a game where the enemy follows the player to try to capture it. But he follows the player on his back, face back, or sideways. Is there any way for the enemy to follow the player facing him?
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player").transform;
playerHealth = player.GetComponent <PlayerHealth> ();
enemyHealth = GetComponent <EnemyHealth> ();
Enemy = GameObject.FindGameObjectWithTag ("Enemy");
nav = GetComponent <NavMeshAgent> ();
}
void Update ()
{
Enemy.transform.LookAt(player);
if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
{
nav.SetDestination(player.position);
transform.Rotate(player.position);
}
else
{
nav.enabled = false;
}
}
}