- Home /
Navmesh Agent Path Not Updating
I have a bunch of navmesh agent's that are all running around in rough formations. For some reason though, for some formations, the path doesn't seem to want to update. Below is the move function I'm using to move the navmesh agents around. I've torn this thing apart and tried everything I could think of so its not the prettiest. Right now those debug logs will come out a single time for most move orders, and every frame when it breaks.
The before and after will list the old destination as the Agent.destination and the new desired destination as the currentTargetPosition.
Is there something obvious that I'm doing wrong? It really is the same move functionality it just seems to break when the units are ordered into a new formation. The only reason I don't think the formation is at fault is if I debug the desired position that I'm attempting to set the navmesh agent destination to and move each unit manually to that in the scene then they are exactly where I would expect. They just won't navigate themselves there for some reason.
I've tried calling ResetPath before i set the new destination. I've tried using the Resume function even though its deprecated. I've tried setting isStopped true and then setting the new destination and then setting isStopped to false. I'm not really sure what else to do to get these things to move.
protected virtual void Move()
{
if (Agent.isOnNavMesh)
{
if(Agent.destination.x != currentTargetPosition.x &&
Agent.destination.y != currentTargetPosition.y &&
Agent.destination.z != currentTargetPosition.z)
{
Agent.ResetPath();
if (debug) Debug.Log("BEFORE : "+Agent.destination + " ??? " + currentTargetPosition);
Agent.SetDestination(currentTargetPosition);
if (debug) Debug.Log("AFTER : " + Agent.destination + " ??? " + currentTargetPosition);
Agent.isStopped = false;
}
if (Agent.remainingDistance <= Agent.stoppingDistance)
{
Agent.isStopped = true;
SetAnimation(IDLE_ANIMATION_ID);
}
else
{
Agent.isStopped = false;
SetAnimation(RUNNING_ANIMATION_ID);
}
}
}
Answer by TSI25 · Mar 08, 2017 at 12:05 AM
Stupid math stuff with the formation calculation. Turns out I was calculating a y for the currentTargetDestination that was way off the navmesh. My bad XD