Reputation: 31
I have a navmesh agent with a set detination to a target, and a Navmesh surface generated using the NavmeshSurface script component. A few weeks ago I had problems with the agent set destination. Now I realised that my agent will only move to it's target if it's in the same tile as itself (those navmesh blue tiles representated when you bake). It's not that it is too far away. It's just that it is in the next tile so it just doesn't work.
am I using the navmesh surface wrong? Or what should I do? Because tiles too big will break it, and tiles too small won't let me use set destination anywhere.
I upload a screenshot of my navmesh and the agent just in case.
And the simple coding I'm using is this, I just choose a random child from a parent to set the destination, right now it is just one for testing:
if (plant_gameobject_father.transform.childCount != 0)
{
chosen_child = Random.Range(0, plant_gameobject_father.transform.childCount - 1);
plant_target = plant_gameobject_father.transform.GetChild(chosen_child);
//Debug.Log(plant_target.transform.position);
agent_.SetDestination(plant_target.position);
Debug.Log(agent_.pathStatus);
Debug.Log(agent_.hasPath);
}
´´´´
This is inside an Ienumerator:
if (plant_target.tag == "planta_grand")
{
Debug.Log(agent_.remainingDistance);
yield return new WaitUntil(() => agent_.remainingDistance < 3.5f);
Debug.Log(agent_.remainingDistance);
agent_.isStopped = true;
agent_.ResetPath();
if (selector_accion == -3)
{
selector_accion = 3;
}
if (selector_accion == -5)
{
selector_accion = 5;
}
}
´´´´
Upvotes: 2
Views: 149