Search Unity

[SOLVED] Navmesh Agent instant turn in direction he moves

Discussion in 'Navigation' started by Wenish, Mar 14, 2018.

  1. Wenish

    Wenish

    Joined:
    Sep 11, 2017
    Posts:
    6
    is there an easy way to turn the navmesh agent really instantly in the direction he moves?
     
    hopetolive likes this.
  2. SM_AF

    SM_AF

    Joined:
    Aug 1, 2017
    Posts:
    23
    In Awake or Start:
    Code (CSharp):
    1. navMeshAgent.updateRotation = false;
    In LateUpdate:
    Code (CSharp):
    1. transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized)
     
  3. Wenish

    Wenish

    Joined:
    Sep 11, 2017
    Posts:
    6
    @SM_AF
    if the agent is at the destination he turns back to his original direction
    u know how to fix this?

    it gives me the warning when the nav mesh agent isnt moving:

    Look rotation viewing vector is zero
    UnityEngine.Quaternion:LookRotation(Vector3)
     
    Last edited: Mar 14, 2018
  4. SM_AF

    SM_AF

    Joined:
    Aug 1, 2017
    Posts:
    23
    Code (CSharp):
    1. if (navMeshAgent.velocity.sqrMagnitude > Mathf.Epsilon)
    2. {
    3.     transform.rotation = Quaternion.LookRotation(navMeshAgent.velocity.normalized);
    4. }
     
  5. Wenish

    Wenish

    Joined:
    Sep 11, 2017
    Posts:
    6
    @SM_AF
    Thanks. It works perfect. like i wanted it
     
    itsjustoneguy and sama-van like this.