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来实现物体的简单自动寻路。

猜你喜欢

转载自blog.csdn.net/feizxiang3/article/details/36713343