NavMeshCut on rotating boxes

I’m working on a 3D TD which requires the player to use a drawing system to create barricades for blocking enemies’ path.

I have a Recast Graph and I would like to update the graph attaching NavMeshCut component to each box collider forming a drawn object. As you can see in the image, a drawn object consists of a set of collider boxes.

My problem is that NavMeshCut component uses a 2D shape to cut the navmesh with. As specified in documentation, if I rotate the object to which NavMeshCut component is attached that shape will be just projected down on the XZ plane, cutting the graph in an unwanted way.

To clarify, here is the result on the navmesh. As you can see in the image below, the graph is badly cut where a collider box is rotated, so enemies can pass through the object.

How can I make a moving and rotating box collider cut the navmesh in real time, according to its position and volume? Maybe using Recast Graph and NavMeshCut isn’t the best solution for me, but I don’t know what else to use to solve my problem.

My version is 4.1.12.

Any help is really appreciated. I’m still a newbie in coding and this is my first project, so examples are really welcome :slight_smile: Please tell me if you need more specific details.

Thanks in advance!


Navmesh cuts currrently only support 2D shapes. As your obstacles have relatively simple shapes, it may be possible for you to create a script which dynamically calculates a rough approximation to the intersection with the obstacle and the ground and makes a navmesh cut use that shape.

Otherwise you could try to use a grid graph / layered grid graph together with the DynamicGridObstacle component. That will update the graph as long as you have colliders on the obstacles. Note however that it uses the bounding box for the attached object (or the attached mesh filter if you have one), for performance reasons you will most likely want a single DynamicGridObstacle component for the whole obstacle, not one for each part of it.