Search Unity

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