Navmesh under obstacle

Hi Aron! I am struggling against a little problem.
I have a simple plane with just one obstacle in the middle. When I bake the navmesh with a recast graph, if I set walkable height/walkable climb to 0 the resulting graph shows that there still is a portion of the navmesh under the obstacle. My AIs can avoid the obstacle (because of the limits of the graph near the border of the obstacle, as you can see from the screenshot), but the problem arise when I try to select some random points to spawn my units.

I use the following code to do that:
GameObject plane = GameObject.Find("Plane"); NNInfo info = AstarPath.active.GetNearest (new Vector3( Random.Range (-plane.transform.localScale.x*10, plane.transform.localScale.x*10), 0, Random.Range(-plane.transform.localScale.z*10, plane.transform.localScale.z*10) )); Vector3 closest = info.clampedPosition; Instantiate(GameObject.CreatePrimitive(PrimitiveType.Cube),closest, Quaternion.identity);
With this code, sometimes units are spawned above the obstacle.
There are two possibilities:

  1. my code is somewhat wrong
  2. the navmesh under the obstacle get considered by get nearest so the unit is placed wrong

What do you think? Am I missing something?

(navmesh settings are indicated in the screenshot)

Hi

If you want to make sure no navmesh at all is generated on an obstacle, you can attach the RecastMeshObj to the object and set the area field to -1, that will make sure it blocks characters from walking on it, but it won’t have a navmesh generated on top of it either.

I tried as you told but the navmesh is still produced under the obstacle :S

(I still have vs. 3.4.0.7, is it possible that RecastMeshObj behaves in this way only with a newer version?)

Oh wait, is the navmesh “under” or “inside” the obstacle?
In that case the RecastMeshObj will not help you, however you can use a NavmeshCut instead.
I don’t think NavmeshCuts are included in 3.4.0.7, but they might be.
For it to work you will need to attach a NavmeshCut component to the obstacle and also create a single TileHandlerHelper on some object in the scene (that will make sure the NavmeshCuts will actually update the graph).

Uh! NavMeshCut + TileHandlerHelper did the trick! Thank you so much :slight_smile: