Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Why does this not move my nave mesh agent?

Discussion in 'Scripting' started by Sean-Powell, Jul 25, 2015.

  1. Sean-Powell

    Sean-Powell

    Joined:
    Dec 18, 2014
    Posts:
    87
    Code (CSharp):
    1. Debug.Log ("moving");
    2.             float xPos =  getMousePositionX();
    3.             float zPos =  getMousePositionZ();
    4.             Vector3 target = new Vector3(xPos, 0.61f, zPos);
    5.             //Instantiate(targetObj, target, Quaternion.identity);
    6.             selectedUnit.GetComponent<NavMeshAgent>().SetDestination(target);
    This code, for some reason does not cause the nav mesh agent to move but if i place a object in the scene and tell it to move to that objects position it does but it won't move to a specified Vector3 is there any way to do this?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Are speed and angularSpeed values correct? Are you sure xPos and zPos are on the navmesh? Is NavMeshAgent behaviour enabled with the correct navmesh linked?
     
  3. Sean-Powell

    Sean-Powell

    Joined:
    Dec 18, 2014
    Posts:
    87
    yea the mouse pos is on the nav mesh and when i put a object in the same position it works. where would i check the speed value?
    it should still be default
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    On the NavMeshAgent component in the inspector.
     
  5. Sean-Powell

    Sean-Powell

    Joined:
    Dec 18, 2014
    Posts:
    87
    yea they are the same as default i even recreated the agent and it still did not work