- Home /
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!
Answer by Terak · Mar 30, 2021 at 01:02 PM
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.
Links: https://docs.unity3d.com/ScriptReference/AI.NavMesh.CalculatePath.html
As a side note this works for me since the walls and doors can open, the movement is a bit more natural and fluid
Answer by andrew-lukasik · Mar 30, 2021 at 12:41 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613031510im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Checking if a non-walkable layer is blocking the path? (NavMeshAgent) 0 Answers
NavMeshAgent resume original position and facing direction C# 0 Answers
My NavMeshAgent doesn't move at all!,Why my NavMeshAgent doesn't move at all? 0 Answers
Player's last location as a Transform 1 Answer
Access navmeshagent calculation data? 0 Answers