Agents to face player

What would be the best approach to have agents rotate to face the player when reaching the end of the path? So if a player walks around an agent it updates its rotation to continue facing them.

Hi

You could do something like this perhaps:

void Update () {
    if (ai.remainingDistance < someThreshold) {
        var dir = ai.destination - transform.position;
        dir.y = 0;
        var rot = Quaternion.LookRotation(dir);
        transform.rotation = Quaternion.Slerp(transform.rotation, dir, Time.deltaTime * 5);
    }
}
1 Like