最优路径:
两点之间的最优路径,是指代价(cost)最小的路径。
每一个NavMesh都分配一个层级,每一个层级对应一定的代价值。
所以总代价值,就是两点之间所经过的NavMesh的层级代价值的和。
当代价值相同时,最优路径便是所有路径中的最短路径了。
不推荐设置层的代价值小于1,这种情况下不能保证获取最佳路径
一共有32个层级,对应32个比特位。其中有三个内置的层级,29个可以由用户自己定义的层级。
三个内置的层级:
Default:默认的层级
Not walkable:无法通过的区域,代价被忽略。
Jump:自动产生的off mesh links的代价
假如场景中有一个自动产生的off mesh link,并且agent中的NavMesh Walkable设置为Default,那么agent将不能通过off mesh link,还要将Jump加入到NavMesh Walkable才还以。
By choosing a layer for a navmesh object, you are also assigning the cost for each unit of distance an agent travels over it. This enables a level designer to divide a scene up into separate navmeshes representing differing traversal costs.
In some situations, most of the ground will be "normal" but there might be some areas that are advantageous to cross. For example, it might be preferable to take a moving walkway or a slide rather than walk the same distance. It is fine to set the cost less than the default value of one for cases like this but you should not attempt to use negative costs to indicate advantages. Since the agent is trying to find the lowest-cost path, he might spend a long time wandering aimlessly around an area of negative cost given that each step actually reduces the cost of the path overall. If you want your game to have mostly normal areas but occasionally have advantageous ground then the best solution is to use a cost greater than one for the "normal" layer and a lower cost for the "advantage" layer.
The cost of a path is a very abstract concept and could involve many different factors but some possible use cases include:-