Search Unity

Navmesh agent velocity stops working with Navmesh obstacle in scene

Discussion in 'Navigation' started by weitay, Oct 28, 2016.

  1. weitay

    weitay

    Joined:
    Aug 5, 2012
    Posts:
    10
    Hi,

    I have a player who is a navmesh agent who is controlled by the keyboard. The following script is for the player

    Code (CSharp):
    1.  public class Player : MonoBehaviour {
    2.  
    3.      NavMeshAgent myNavMeshAgent;
    4.  
    5.      void Awake()
    6.      {
    7.          myNavMeshAgent = GetComponent<NavMeshAgent>();
    8.      }
    9.  
    10.      void FixedUpdate()
    11.      {
    12.          float v = Input.GetAxisRaw("Vertical");
    13.          float h = Input.GetAxisRaw("Horizontal");
    14.  
    15.          Vector3 walkVector;
    16.          float walkSpeed = 6f;
    17.          //Move position
    18.          walkVector = new Vector3(h, 0f, v);
    19.          walkVector =  walkVector.normalized * walkSpeed;
    20.          myNavMeshAgent.velocity = walkVector;
    21.  
    22.      }
    23. }
    This works fine but the moment I add a NavMesh Obstacle with carve set to true the player refuses to move! At first I thought it was because the player also has a rigidbody but when I removed that it still dosen't move!
     
    howong likes this.