본문 바로가기
프로그래밍/유니티

Unity NavMesh #6 실시간 네비메시 빌드 3

by 넋두리- 2021. 2. 22.

Unity NavMesh Building Component 예제도 어느새 절반을 넘게 했네요.

 

이전의 포스팅과 마찬가지로

혹시 NavMesh Building Component를 다운받지 않았으면 아래 링크에서 먼저 다운로드 해주세요.

다운로드 : github.com/Unity-Technologies/NavMeshComponents

 

Unity-Technologies/NavMeshComponents

High Level API Components for Runtime NavMesh Building - Unity-Technologies/NavMeshComponents

github.com

 

5_sliding_window_terrain.unity를 열어줍니다.

 

오늘도 실시간 네비메시 빌드와 관련된 내용입니다.

하이어라키에 Terrain GameObject를 보면 NavMeshBuildSource를 생성해주는 역할을 하는

NavMeshSourceTag 스크립트가 붙어 있습니다. 

Terrain으로 실시간 네비메시 빌드를 하는 예제 같군요.

 

5_sliding_window_terrain

 

지난번 예제들과 에이전트를 기준으로 한 로컬 바운드에서 네비 메시 빌드를 하고 있습니다.

자세히보면 네비 메시 중간에 hole이 여기저기 있네요.

 

NavMesh Build with Terrain

 

빨간 동그라미로 표시한 부분들에 구멍들이 있습니다.

네비 메시 빌드 과정에서 Agent 세팅 값을 기준으로 갈 수 있는 영역인지 아닌지 판단을 하도록 되어있어요.

 

NavMeshAgent Setting

 

NavMeshAgent 세팅에 Radius, Height, Step Height, Max Slope 모두 네비 메시를 생성하는데 관여를 합니다.

 

네비 메시 빌드과 관련해서 더 궁금하시면 아래 도큐먼트들을 참조해주세요!

 

NavMeshAgent : docs.unity3d.com/kr/current/Manual/class-NavMeshAgent.html

 

내비메시 에이전트 - Unity 매뉴얼

NavMeshAgent 컴포넌트는 목표를 향해 움직일 때 서로를 피해가는 캐릭터 생성에 유용합니다. 에이전트는 내비메시를 이용하여 게임 월드에 대해 추론하고 서로 또는 기타 움직이는 장애물을 피할

docs.unity3d.com

 

NavMesh Bake : docs.unity3d.com/kr/current/Manual/nav-AdvancedSettings.html

 

고급 내비메시 베이크 설정 - Unity 매뉴얼

Min Region Area 고급 빌드 설정을 사용하여 연결되지 않은 작은 내비메시 영역을 제거할 수 있습니다. 표면 영역이 특정 값보다 작은 내비메시 영역은 제거됩니다.

docs.unity3d.com

 

NavMeshSourceTag 함수는 두번째 예제인 twosouls.tistory.com/7

 

Unity NavMesh #3 실시간 네비메시 빌드

오늘은 NavMesh Building Component의 두번째 예제를 살펴보려고 합니다. 두번째 예제에는 runtime navmesh build, real-time navmesh build와 관련된 내용이 있습니다. 이게 무슨 내용이냐구요? 예제를 통해서 천..

twosouls.tistory.com

위 포스팅에서 알아봤었고,

 

이번에는 NavMeshBuildingSource의 데이터 타입인 NavMeshBuildingSourceShape에 대해서 더 알아보려고해요.

 

namespace UnityEngine.AI
{
    //
    // 요약:
    //     Used with NavMeshBuildSource to define the shape for building NavMesh.
    public enum NavMeshBuildSourceShape
    {
        //
        // 요약:
        //     Describes a Mesh source for use with NavMeshBuildSource.
        Mesh = 0,
        //
        // 요약:
        //     Describes a TerrainData source for use with NavMeshBuildSource.
        Terrain = 1,
        //
        // 요약:
        //     Describes a box primitive for use with NavMeshBuildSource.
        Box = 2,
        //
        // 요약:
        //     Describes a sphere primitive for use with NavMeshBuildSource.
        Sphere = 3,
        //
        // 요약:
        //     Describes a capsule primitive for use with NavMeshBuildSource.
        Capsule = 4,
        //
        // 요약:
        //     Describes a ModifierBox source for use with NavMeshBuildSource.
        ModifierBox = 5
    }
}

 

Shape에는 MeshFilter 컴포넌트가 있는 Mesh, Terrain 컴포넌트가 있는 Terrain, 원형을 갖고있는 Primitive Box, Sphere, Capsule 그리고 ModifierBox가 있습니다.

 

Mesh은 sourceObject에 MeshFilter의 sharedMesh를, Terrain은 sourceObject에 Terrain.terrainData를 넣어주면 됩니다.

ModifierBox 같은 경우는 NavMeshSurface에서 NavMeshBuildingSource를 Collect하는 타입 중에 Volume이란 것이 있는데 아마 거기서 쓰이는 것 같아요.

나머지 Box, Sphere, Capsule은 각 요소에 맞춰서 size를 넣어주면 됩니다.

 

아래 도큐먼트에 상세히 나와있습니다.

docs.unity3d.com/ScriptReference/AI.NavMeshBuildSource.html

 

Unity - Scripting API: NavMeshBuildSource

Their shape can be one of the following: mesh, terrain, box, sphere, or capsule. Each of them is described by a NavMeshBuildSource struct. You can specify a build source by filling a NavMeshBuildSource struct and adding that to the list of sources that are

docs.unity3d.com

 

오늘은 사실 설명보다는 도큐먼트 참조를 통해서 대부분 넘어갔는데요,

제일 좋은 건 역시 공식 도큐먼트인 것 같습니다.

API의 레퍼런스를 찾아가 함수나 변수에 있는 주석만으로 이해가 안가면

도큐먼트에 대부분 다 내용이 나와있더라구요.

 

오늘 5번 예제랑 지난 4번 예제는 좀 비슷한 내용인 것 같아서 흥미가 덜할 수 있을 것 같네요.

다음 예제는 잠깐 봤는데 색다른 내용인 것 같아요.

 

다음 포스팅에서 뵙겠습니다!

댓글