Unity 之Navigation烘焙

来源:互联网 发布:java的分支语句课件 编辑:程序博客网 时间:2024/04/28 05:55

Building a NavMesh

在Unity中,NavMesh  的生成操作需要Navigation窗口(在Window> Navigation

在你的场景中构建NavMesh只需要4个步骤:

  1. 选择场景中需要生成寻路的几何体-可行走表面和障碍物。
  2. 在NavMesh面板中选择需要烘焙寻路的物体,检测是否勾选Navigation Static.
  3. 根据你的agent大小来调整bake 面板的设置。
    • Agent Radius : agent可以距离墙体 ,窗户或边缘多近的距离。
    • Agent Height : agent可以通过的最低的空间高度。
    • Max Slope : agent可以直接行走上去的最小坡度。
    • Step Height:  agent可以踩上(走上)的障碍物最高高度。
  4. 点击bake按钮烘焙NavMesh。

当你的Navigation窗口打开并且可见时,烘焙的NavMesh结果在场景中会以蓝色的覆盖层在物体的几何体表面显示。

When baking is complete, you will find a NavMesh asset file inside a folder with the same name as the scene the NavMesh belongs to. For example, if you have a scene called First Level in the Assets folder, the NavMesh will be at Assets > First Level > NavMesh.asset.当烘焙结束后,你可以找到一个名字和你的场景名一样的文件夹,里面有一个NavMesh的资源文件,是属于这个场景的NavMesh。

让物体可烘焙的其他方法

直接选择物体在Inspector面板顶部的Static 菜单,你可以直接选择Navigation Static,而不用再打开Navigation 窗口。

NavMesh烘焙的高级设置

最小区域面积

Min Region Area 允许你剔除掉小的非连接NavMesh区域,当NavMesh区域小于指定值时将被剔除。

请注意:有些区域可能无法被移除,尽管有Min Region Area 的设置,原因是NavMesh的构建是一个个的网格并行构建。当一个区域横跨两个网格将不会被移除,因为区域修剪过程中无法获取到周围的网格。

Voxel Size 立体像素尺寸

Manual voxel size :允许你改变烘焙操作过程中的精确性。

Navigation在构建寻路网格过程中,第一遍会把场景光栅化为体素,然后提取可行走区域,最后可行走区域会烘焙成网格。因此体素尺寸Voxel Size的决定了寻路网格烘焙的精准性。

提示:默认的体素设置最好的权衡了准确性和烘焙速度。在烘焙场景寻路的过程中,体素的增加会造成4x倍的内存消耗和4x倍的时间消耗。因此通常,你不需要自己去设置Voxel Size。


Smaller Agent Radius

系统烘焙寻路是也会减小voxel size。如果你的agent尺寸保持不变,可能不需要增加NavMesh的构建分辨率。

更简单的方法如下所示:

  1. 设置你的半径为真实agent半径
  2. 打开Manual Voxel Size,这会保持当前的voxel的大小并且冻结它。
  3. 人为的将你的Agent Radius设置小,因为你已经勾选了Manual Voxel Size ,voxel size将不会改变。

Height mesh : 允许你为角色提供更精准的位置。

While navigating, the NavMesh Agent is constrained on the surface of the NavMesh. Since the NavMesh is an approximation of the walkable space, some features are evened out when the NavMesh is being built. For example, stairs may appear as a slope in the NavMesh. If your game requires accurate placement of the agent, you should enable Height Mesh building when you bake the NavMesh. The setting can be found under the Advanced settings in Navigation window. Note that building Height Mesh will take up memory and processing at runtime, and it will take a little longer to bake the NavMesh.

尽管普通的NavMesh 已经可以很好的运行,但是由于NavMesh只是一个近似的可行走的空间,只保持了一些均衡的特性,如果你的游戏agent需要更精准的行走位置,你可以启用高度网格Height Mesh,

注意:高度网格Height Mesh将占用你“运行时”的内存和cpu,并且需要更多的烘焙时间。


翻译原文:https://docs.unity3d.com/Manual/Navigation.html
5 0