- Home /
Can't get NavMeshAgent move. NavMeshAgent ignores destination property
Hi! I'm using Unity 4.0.0f7. Now, I'm trying to be familliar with NavMeshes and NavMeshAgents. I created a simple plane, made it Navigation Static, Baked it. Created Cube, added NavMeshAgent to it. Attached a script:
public var target:Transform;
function Update () {
GetComponent(NavMeshAgent).destination = target.position;
Debug.Log(GetComponent(NavMeshAgent).destination+" "+GetComponent(NavMeshAgent).pathStatus+" "+target.position);
}
After first unlucky try, I've added to the script this construction: Debug.Log(Debug.Log(GetComponent(NavMeshAgent).destination) into Update() function. Log says that navmesh totaly ignore my "GetComponent(NavMeshAgent).destination" construction.
"target" is simple capsule, placed on the opposide side of plane. "pathStatus" says "PathComplete".
Answer by twobob · Sep 17, 2014 at 07:10 PM
In my case it was simply that the transform of the target was actually just outside the "Valid Y range" for the destination to "snap" to the NavMesh.
No easily discernible warning is offered in this instance. If the agent was too far from the mesh this would cause a: "SetDestination can only be called on an active agent that has been placed on a NavMesh." when invoking a NavMesh related function ('SetDestination' in this example). However there is no immediate: "SetDestination can only be called on a position within /n/ of the NavMesh.", it simply silently fails. Caveat discipulus!.
Not sure how wide a range that is yet, looks to be about "+-12" just on basic testing.
Hope it helps someone else save some time. There are some helper functions to determine valid mesh points that I also have not explored. That too might be a sensible wrapper for this call.
Answer by scadl · Mar 23, 2013 at 10:42 AM
Hello to everyone! I've finally figure out whats wrong! But I had never imagine, that this coud be reason! So when you Bake NavMesh from your geometry, there are some parameters. In "General" part, there are two parameters: "Radius" and "Height". So, this parameters have nothig with NavMesh generation! Instead this parameters LIMITS NavMeshAgents, to work with this NavMesh. So If you want, that your NavMeshAgents travel over this NavMesh, you should place "Height" and "Radius" of the smallest of your NavMeshAgents into this NavMesh parameter before Baking.
You are correct, I had the same problem. But ins$$anonymous$$d of making the Nav$$anonymous$$esh bake settings for radius and height smaller, I increased the size of my agent. It had to be small, so I kept the small mesh visible and parented it to a cube of big enough sizes and disabled that cube's $$anonymous$$eshRenderer. Did the trick. Thanks.
Answer by Ghikya · Aug 08, 2016 at 02:17 PM
Also sometimes when you play with NavMeshAgent speed, if you set it to 0 then you forget to set it back to a bigger value, in this case setDestination simple will not have any affect. So you should check this at first before checking other solutions.
Thank you sir. I have been messing with this on a few occasions! Was indeed the speed.
Answer by BLarentis · Mar 22, 2013 at 08:07 PM
Hello, try to create an C# script and use this code:
public GameObject target;
// Update is called once per frame
void Update () {
this.gameObject.GetComponent<NavMeshAgent>().destination = target.transform.position;
}
put the script in your Cube agent. I used this code here and it worked. If this dosen't work, you might have a problem with something else. If this work, you might need to check out how to access your NavMeshAgent component with Java script. Hope this helped you! Take care.
Sorry, I'm not advanced C# user, so I pasted your example like this:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : $$anonymous$$onoBehaviour {
public GameObject target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.gameObject.GetComponent().destination = target.transform.position;
}
}
But compiler Says:
Assets/NewBehaviourScript.cs(16,33): error CS0411: The type arguments for method `UnityEngine.GameObject.GetComponent()' cannot be inferred from the usage. Try specifying the type arguments explicitly
String 16, is the string with main construction, and column 33 is where "destination" placed
First - thanks for answer. Second - no, even this script doesn't work...
Attaching my Demo Project. The problem is in "scene2". This is Unity4 project. If you can, please check it, and tell me, whats my mistake? http://www.mediafire.com/?cq5q5ayiww56ia9
The project are clean. The are some simple models from $$anonymous$$aya and Sketchup, but they are in "scene1"
This site made an error with the format of my code, the correct code linde inside Update is the one inside the image attached. Take Care.
Yes, I corrected code to exatly this. But it's still doesn't work...
Answer by scadl · Mar 23, 2013 at 12:47 PM
Also, if you're NavMesh Baking some sort of huge or extra scaled landscape, don't forget to tune "Width inaccuracy %" and "Height inaccuracy %", because they are controls how much diffrence can be between start point of your agents and destination!
Your answer
Follow this Question
Related Questions
Navmesh Path is shown even between disconnected regions.? 0 Answers
Lack of Bi-Direction OffMeshLinks for Jumping Up? 0 Answers
Instantiated objects at beginning of runtime are messing with the pathing for my NavMesh. 0 Answers
Find the nearest location and move to a target outside Navigation Mesh? 1 Answer
NavMesh Agent glitches on navmesh edges 2 Answers