1. 程式人生 > >unity3d之Navigation <一>

unity3d之Navigation <一>

今天打算實現一個怪物在場景中的巡邏,便開始接觸學校Navigation

下面是一些學習記錄:

首先是官方資料的親筆翻譯

導航網格,一個路徑尋找系統需要一種方式來呈現遊戲世界中那些部分是被遊戲角色可以到達的,同時也需要一種方式來決定兩點之間可行的路線並選擇出最佳路線。

而網格(類似於3D圖形學裡的概念)是解決上述兩個問題的很好方案。可到達的區域可由網格多邊形來劃定,同時通過網格的可行路線..blablabla

在實際中,圖形網格太過細緻導致對導航很不高效。對此,一個智慧的系統,用一種更簡單而不可見的網格稱為導航網格(navmesh)來補充地面網格。幸運的是,有很多技術來自動生成高效的navemesh,這個計算navemesh的過程被稱為 baking.

在unity, navmesh的生成需要從導航視窗操作(window->Navigation)

 

如果,Scene Filter選項是簡單的限定在場景檢視或層級檢視中被選的的物體。其他選項用來應用被選擇的物件。

粗略的說,它們允許你在導航網格的可行走區域中包含或去除一個物體。你必須將物體標記為Navigation Static才可以將它包含如導航網格。你也可以設定導航層為default或者not Walkable. 通常the walkable areas包含遊戲世界中的地面、斜坡、橋之類的,而不可行走區域就是牆等不可穿越障礙物。

接下來選擇Bake進行進一步設定..

Of particular note are the General settings. The Radius determines how close a navigating character can get to a wall and consequently the width of the narrowest gap between two walls that can it can squeeze through. The Height refers to the height of the “ceiling” above the navmesh surface - an area may not be reachable simply because there is not enough headroom for the character. TheMax Slope

 parameter sets the threshold of steepness where a ramp becomes a wall while the Step Height is the maximum height of bump or step in the floor surface that is ignored by the character (any step greater than this height results in a disconnected walkable area rather than a continuation of the same area).

With these parameters set, you can click the Bake button to compute the navmesh. The baking usually takes place very quickly and the resulting navmesh will be shown in the Scene as an overlay on the underlying level geometry. You may need a few attempts based on what you see in the scene before you get the settings for the navmesh just right.

懶得翻譯了,但是基本的知識點都有了,我們可以為物體新增一個Nav Mesh Agent並新增指令碼設定GetComponent<NavMeshAgent>().destination來實現物體的簡單自動尋路。