Best way to rotate a NavMesh AI to face the player or a specific direction?

I am coding AI for a stealth game and what I need is to be able to A: Make it rotate to face the player once it’s close enough (I don’t want to just use lookat, I want a smooth natural rotation), and B: when it returns to it’s original point, to also rotate to the direction it was originally facing. How does one do this while keeping the Nav Mesh Agent working at all times?

G’day! You may have already figured this out by now, but I just ran into the same issue! I solve this issue by using a Quaternion.Lerp


So essentially how I achieved this was by.


this.transform.rotation = Quaternion.Lerp(this.transform.rotation, aiLookPosition.rotation, Time.deltaTime);
  • this.transform.rotation //AI’s current/ literal rotation.
  • AILookPosition //A empty gameobject placed above the AI to conduct raycasts/ constantly look at the player once detected.

This essentially gave me the result you where looking for!


Thanks, Shanks.