NavMesh Layers (Pro only)

最优路径:

两点之间的最优路径,是指代价(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.

a long journey over low-cost ground can be more expensive than a short journey over high-cost ground. Sometimes this will give plausible behaviour, for example when a character risks a shortcut down a dark alleyway rather than a very long round trip. However, the behaviour might sometimes be "rational" but unrealistic. A car can be made to favour roads by assigning them a low cost, but it should never normally drive through somebody's garden just to avoid a hairpin bend. Careful choice and testing of costs is sometimes necessary and it might be easier to redesign a level slightly rather than juggle with a complex setup of different navmesh 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:-

  • Difficulty or desirability of terrain: A character will favour a route over easier ground but might make a quick detour to avoid a long round trip. For example, you would usually step around a small puddle but you might risk a bit of wading if the puddle covers the footpath and the alternative route is much longer.
  • Risk: It might be in the nature of your game that thieves lurk in dark alleyways and snakes live in long grass. An intelligent character would usually avoid places like this.
  • Visibility: Characters escaping from prison would want to stay away from CCTV cameras and guards' patrol routes.
  • Exposure: An attack force would tend to keep close to walls, cars and other large and substantial objects, breaking cover only when necessary.
  • Damage: fire, electrified floors and pools of acid should normally be avoided but they may need to be braved if they are blocking the only escape route.

 

你可能感兴趣的:(NavMesh Layers (Pro only))