Why does my navmesh agent take longest path? (VIDEO)


1


I’m trying to figure out why my navmesh agent would rather take the longest path to an object even if hes standing right next to it…


Does anyone know why this would be happening?

This is the navmesh after the first gate is opened



If I go to that left most gate first, he just opens it like the other, but then if I go to the top gate, he does the same thing… runs through the first opened gate to the outside of the gate he should have just ran straight to… no idea why


UPDATE: The gates have a Navmesh Obstacle on them: Per the docs “The Nav Mesh Obstacle component allows you to describe moving obstacles that Nav Mesh Agents should avoid while navigating the world” - I’m using a navmesh obstacle to alter the navmesh after a gate is opened - disabling the navmesh obstacle fixes the behavior - the problem is my player can just run through gates. I can stop movement in the trigger, but am wondering if there is a way to avoid it?

Because some of area did not have blue area(walkable path)

In navmesh Navigation window(Bake Tab). Change radius of agent from 0.5f → 0.25f or your agent size. Will fix your problem

The easiest solution for this was to manipulate the end point of the destination. I’m still not sure why, but It was like I was getting random results: will the agent open the gate on the correct side or will he run around the map to the other side?


Ultimately I just subtract 1 unit from the path towards the player, so that the destination was always on the side of the fence that the player is on:

destination = hit.transform.position;
distance = Vector3.Distance(transform.position, destination) - 1.0f;
    
moveToPos = (destination - transform.position).normalized * distance;
moveToPos = transform.position + moveToPos;

Thanks to @NoDumbQuestion for suggesting I build my own path