The NavMesh Obstacle component allows you to describe moving obstacles that NavMesh Agents should avoid while navigating the world (for example, barrels or crates controlled by the physics system). While the obstacle is moving, the NavMesh Agents do their best to avoid it. When the obstacle is stationary, it carves a hole in the NavMesh. NavMesh Agents then change their paths to steer around it, or find a different route if the obstacle causes the pathway to be completely blocked.
프로퍼티 | 기능 |
---|---|
Shape | 장애물 지오메트리의 모양입니다. 오브젝트 모양에 가장 적합한 것을 선택해야 합니다. |
Box | |
Center | 변환 포지션에 대한 박스의 상대적인 중심입니다. |
Size | 상자의 크기입니다. |
Capsule | |
Center | 변환 포지션에 대한 캡슐의 상대적인 중심입니다. |
Radius | 캡슐의 반지름입니다. |
Height | 캡슐의 높이입니다. |
Carve | Carve 체크박스를 선택하면 내비메시 장애물이 내비메시에 구멍을 만듭니다. |
Move Threshold | Unity는 내비메시 장애물이 Move Threshold를 통해 설정한 거리보다 많이 움직인 경우 움직인다고 간주합니다. 이 프로퍼티는 움직이는 파인 구멍을 업데이트하는 임계 거리를 설정하는 데 사용합니다. |
Time To Stationary | 장애물이 정지되었다고 간주할 때까지 기다리는 시간(초)입니다. |
Carve Only Stationary | 이 옵션을 활성화하면 장애물이 정지되어 있을 때만 구멍을 팝니다. 자세한 내용은 아래의 내비메시 장애물 이동 논리를 참조하십시오. |
NavMesh obstacles can affect the NavMesh agent’s navigation during the game in two ways: obstructing and carving.
When Carve is not enabled, the default behavior of the NavMesh obstacle is similar to that of a Collider. NavMesh agents try to avoid collisions with the NavMesh obstacle, and when close, they collide with the NavMesh obstacle. Obstacle avoidance behaviour is very basic, and has a short radius. As such, the NavMesh agent might not be able to find its way around in an environment cluttered with NavMesh obstacles. This mode is best used in cases where the obstacle is constantly moving (for example, a vehicle or player character).
When Carve is enabled, the obstacle carves a hole in the NavMesh when stationary. When moving, the obstacle is an obstruction. When a hole is carved into the NavMesh, the pathfinder is able to navigate the NavMesh agent around locations cluttered with obstacles, or find another route if the current path gets blocked by an obstacle. It’s good practice to turn on carving for NavMesh obstacles that generally block navigation but can be moved by the player or other game events like explosions (for example, crates or barrels).
Unity treats the NavMesh obstacle as moving when it has moved more than the distance set by the Carve > Move Threshold. When the NavMesh obstacle moves, the carved hole also moves. However, to reduce CPU overhead, the hole is only recalculated when necessary. The result of this calculation is available in the next frame update. The recalculation logic has two options:
Only carve when the NavMesh obstacle is stationary
Carve when the NavMesh obstacle has moved
This is the default behavior. To enable it, tick the NavMesh obstacle component’s Carve Only Stationary checkbox. In this mode, when the NavMesh obstacle moves, the carved hole is removed. When the NavMesh obstacle has stopped moving and has been stationary for more than the time set by Carving Time To Stationary, it is treated as stationary and the carved hole is updated again. While the NavMesh obstacle is moving, the NavMesh agents avoid it using collision avoidance, but don’t plan paths around it.
Carve Only Stationary 는 일반적으로 성능의 관점에서 최선의 선택이고 내비메시 장애물과 연관된 게임 오브젝트가 물리를 통해 제어되는 경우에 적합합니다.
To enable this mode, untick the NavMesh obstacle component’s Carve Only Stationary checkbox. When this is unticked, the carved hole is updated when the obstacle has moved more than the distance set by Carving Move Threshold. This mode is useful for large, slowly moving obstacles (for example, a tank that is being avoided by infantry).
Note: When using NavMesh query methods, you should take into account that there is a one-frame delay between changing a NavMesh obstacle and the effect that change has on the NavMesh.
Creating a NavMesh Obstacle - Guidance on creating NavMesh obstacles.
Inner Workings of the Navigation System - Learn more about how NavMesh obstacles are used as part of navigation.
NavMesh Obstacle scripting reference - Full description of the NavMesh obstacle scripting API.
NavMeshObstacle