Manual
Manual
Obstacles
An obstacle is something agents go around while the game plays: a crate pushed into a doorway, a door that closes, a car that parks. This page covers the Nav Mesh Obstacle 3D and its twin in 2D, the two ways agents go around it, and how an obstacle that moves is followed.
Nav Mesh Obstacle 3D
A Nav Mesh Obstacle 3D is a box or an upright cylinder, placed and scaled by its entity. It acts only while the game plays, on every navmesh it stands on.
| Field | What it does |
|---|---|
| Shape | Box, turned as its entity is about the up axis, or Cylinder, upright. Box at first. |
| Center | Its middle, from its entity's, in the entity's units. |
| Size | The box's size each way, in the entity's units. 1 each way at first. |
| Radius | The cylinder's radius, in the entity's units. 0.5 at first. |
| Height | The cylinder's height, in the entity's units. 2 at first. |
| Carve | Whether it is cut out of the navmesh, so paths are planned around it rather than only steered around. Off at first. |
| Move Threshold | How far it moves, in meters, before it counts as moving. 0.1 at first. |
| Time To Stationary | How long it stands still, in seconds, before it is cut out of the navmesh. 0.5 at first. |
| Carve Only Stationary | Whether it is cut out only while it stands still. Off, it is cut out again each time it moves, which costs more. On at first. |
A box turns with its entity about the up axis alone, as the navmesh is cut seen from above.
Nav Mesh Obstacle 2D
A Nav Mesh Obstacle 2D is the same for a navmesh in 2D: a box or a circle on the XY plane, placed, turned and scaled by its entity. Its Shape is Box, turned as its entity is about Z, or Circle, its Radius scaled by the larger of its entity's X and Y. It has no Height; its other fields are the 3D one's, and it is steered around and cut out as below.
Steered around
An obstacle that does not carve is steered around: the agents near it turn aside as they turn aside for each other, by their Avoidance. Their paths still go through it, so an obstacle that fills a doorway sends no agent another way: carve it for that.
Agents steer around an obstacle as a circle, a box as wide as its longer side, so a long thin obstacle is given more room than it takes. Steering suits what moves all the time, such as a rolling barrel or another vehicle.
Carving
With Carve on, the obstacle is cut out of the navmesh once it has stood still for Time To Stationary. The hole is grown by the agent's radius, as walls are, so agents keep clear of its edges. Paths are planned around it, and a doorway it fills is no longer a way through: an agent sent beyond finds another way, or gets as close as it can.
Only the tiles the obstacle covers are built again, so cutting one in costs little even in a large level. A navmesh holds up to 256 obstacles cut in at once.
Obstacles that move
An obstacle is moving once it has gone farther than Move Threshold from where it last stood still. Then:
- With Carve Only Stationary on, its cut is taken out, and it is steered around until it has stood still for Time To Stationary again, when it is cut out where it is then.
- With Carve Only Stationary off, it is cut out again where it is each time it moves past Move Threshold. Paths follow it closely, at the cost of building tiles again as it goes.
Move an obstacle by moving its entity. Its fields can change while the game plays too, so a gate, here with a Gate component of your own, can carve only while it is shut:
[AbyssSystem][MethodImpl(MethodImplOptions.AggressiveInlining)]private static void Block(ref NavMeshObstacle3D obstacle, in Gate gate){ obstacle.Carve = gate.Shut; // shut, the way is cut; open, agents walk through}What obstacles cut lasts only while the game plays. When it stops, each navmesh is read again from its file, as it was baked.
Seen in the Scene view
A picked obstacle is drawn as its shape where its entity puts it, on the XY plane in 2D: orange when Carve is on, gray-blue otherwise. The Navigation window's Show Agents draws every obstacle, not only those picked.
In the Scripting API
- NavMeshObstacle3D: something agents go around, with NavMeshObstacleShape3D.
- Navigation3D: its
Carvedcount, how many obstacles are cut out while the game plays. - NavMeshObstacle2D, with NavMeshObstacleShape2D, and Navigation2D: the same in 2D.
