Reference a Navmesh local "island"

Hi all,

I have an AI NavMeshAgent randomly picking a spot on the navmesh and then moving over to it. The problem is that I need them to pick a random spot on the NavMesh island they are currently on. Is there a way to get those details?

See below image for reference (Once the doors/walls are opened the navmesh is expanded allowing the agent to walk to other rooms):

Thanks in advance!

One way of dealing with this would be to just precompute a lookup table of Bounds and their matching arrays of points.

(Bounds bounds,Vector3[] pool)[] lookup;

Brute-force way of doing that would be to, for example, generate a lot of random points and then group them together based on whenever a navigation path can be computed between them. When that is done you calculate Bounds for every group and vous voilà!

Runtime, your nav agents could then start with finding specific bounds they’re in and just pick one of the matching destination points from given pool.

Thank you for the suggestion, but I found a different way. Since I’m picking a random spot on the mesh, I’m using CalculatePath to check if the agent can find a way to the destination. I check the path with the parameter “NavMeshPathStatus.PathComplete” and go from there.


As a side note this works for me since the walls and doors can open, the movement is a bit more natural and fluid