导航和寻路外文翻译资料

 2022-09-30 11:09

Navigation and Pathfinding

The Navigation system allows you to create characters that can intelligently move in the game world. The navigation system uses navigation meshes to reason about the environment. The navigation meshes are created automatically from your Scene geometry. Dynamic obstacles allow alter the navigation of the characters at runtime, and off-mesh links let you to build specific actions such as opening doors, or jumping down from a ledge. This section describes Unityrsquo;s navigation and pathfinding in detail.

Navigation Overview

This section will dive into the details on building NavMeshes for your scene, creating NavMesh Agents, NavMesh Obstacles and Off-Mesh Links.

Navigation System in Unity

The Navigation System allows you to create characters which can navigate the game world. It gives your characters the ability to understand that they need to take stairs to reach second floor, or to jump to get over a ditch. The Unity NavMesh system consists of the following pieces:

NavMesh (short for Navigation Mesh) is a data structure which describes the walkable surfaces of the game world and allows to find path from one walkable location to another in the game world. The data structure is built, or baked, automatically from your level geometry.

NavMesh Agent component help you to create characters which avoid each other while moving towards their goal. Agents reason about the game world using the NavMesh and they know how to avoid each other as well as moving obstacles.

Off-Mesh Link component allows you to incorporate navigation shortcuts which cannot be represented using a walkable surface. For example, jumping over a ditch or a fence, or opening a door before walking through it, can be all described as Off-mesh links.

NavMesh Obstacle component allows you to describe moving obstacles the agents should avoid while navigating the world. A barrel or a crate controlled by the physics system is a good example of an obstacle. While the obstacle is moving the agents do their best to avoid it, but once the obstacle becomes stationary it will carve a hole in the navmesh so that the agents can change their paths to steer around it, or if the stationary obstacle is blocking the path way, the agents can find a different route.

Inner Workings of the Navigation System

When you want to intelligently move characters in your game (or agents as they are called in AI circles), you have to solve two problems: how to reason about the level to find the destination, then how to move there. These two problems are tightly coupled, but quite different in nature. The problem of reasoning about the level is more global and static, in that it takes into account the whole scene. Moving to the destination is more local and dynamic, it only considers the direction to move and how to prevent collisions with other moving agents.

Walkable Areas

The navigation system needs its own data to represent the walkable areas in a game scene. The walkable areas define the places in the scene where the agent can stand and move. In Unity the agents are described as cylinders. The walkable area is built automatically from the geometry in the scene by testing the locations where the agent can stand. Then the locations are connected to a surface laying on top of the scene geometry. This surface is called the navigation mesh (NavMesh for short).

The NavMesh stores this surface as convex polygons. Convex polygons are a useful representation, since we know that there are no obstructions between any two points inside a polygon. In addition to the polygon boundaries, we store information about which polygons are neighbours to each other. This allows us to reason about the whole walkable area.

Finding Paths

To find path between two locations in the scene, we first need to map the start and destination locations to their nearest polygons. Then we start searching from the start location, visiting all the neighbours until we reach the destination polygon. Tracing the visited polygons allows us to find the sequence of polygons which will lead from the start to the destination. A common algorithm to find the path is A* (pronounced “A star”), which is what Unity uses.

Following the Path

The sequence of polygons which describe the path from the start to the destination polygon is called a corridor. The agent will reach the destination by always steering towards the next visible corner of the corridor. If you have a simple game where only one agent moves in the scene, it is fine to find all the corners of the corridor in one swoop and animate the character to move along the line segments connecting the corners.

When dealing with multiple agents moving at the same time, they will need to deviate from the original path when avoiding each other. Trying to correct such deviations using a path consisting of line segments soon becomes very difficult and error prone.

Since the agent movement in each frame is quite small, we can use the connectivity of the polygons to fix up the corridor in case we need to take a little detour. Then we quickly find the next visible corner to steer towards.

Avoiding Obstacles

The steering logic takes the position of the next corner and based on that figures out a desired direction and speed (or velocity) needed to reach the destination. Using the desired velocity to move the agent can lead to collision with other agents.

Obstacle avoidance chooses a new velocity which balances between moving in the desired direction and preventing future collisions with other agents and edges of the navigation mesh. Unity is using reciprocal velocity obstacles (RVO) to predict and prevent collisions.

Moving

剩余内容已隐藏,支付完成后下载完整资料


导航和寻路

导航系统允许你创建一个可以在游戏世界中智慧地移动的人物。导航系统使用导航网格响应周围的环境。导航网格是根据你的场景几何自动创建的。动态障碍物允许在运行时改变人物的导航,断离网格连接可以让你创造一些特殊的动作行为,比如开门或者从窗台跳下来。本节详细描述了Unity中的导航和寻路。

导航概览

本节会深入研究为你的创建导航网格,导航代理,导航障碍物和断离网格连接。

Unity中的导航系统

导航系统允许你创建一个可以在游戏世界中导航的人物。它使你的人物拥有可以理解上台阶或者跳过一个沟壑的能力。Unity中的导航系统包含以下几个方面:

NavMesh(Navigation Mesh的简写)是一个描述了游戏世界中可行走表面的数据结构,它允许你找到一条从一个可行走区域到达另一个可行走区域的路径。该数据结构自动从你的场景几何中创建或者烘焙。

导航代理组件(NavMesh Agent)帮助你创建可以相互躲避的人物当他们朝着各自的目标点移动时 。代理使用导航网格对整个游戏世界作出响应,并且他们就像移动到障碍物时一样知道如何相互躲避。

断离网格连接组件(Off-Mesh Link)允许你合并不能使用可行走表面表示的导航路径。例如,跳过一个沟壑或者篱笆,或者在走进去之前打开一个门,都可以被描述为断离网格连接。

导航网格障碍物组件(NavMesh Obstacle)允许你描述一个代理到游戏世界中导航时躲避的可移动 的障碍物。一个被物理系统控制的圆筒或者木桶是一个很好的障碍物例子。当障碍物移动时代理尽可能的去躲避它,但是一旦障碍物变成了静止的它会在导航网格中切开一个洞,因此代理可以改变他们的路径在障碍物周围运动,或者如果这个静止的障碍物阻断了路径,代理可以找到一个不同的路径。

导航系统的内部工作方式

当你想智慧地在游戏世界中移动人物时(或者代理被称作AI),你需要解决两个问题:如何响应场景以便找到目标,然后如何移动到那去。这两个问题是紧紧在一起的,但是很自然又是不同的。响应场景问题是更加全局和静态的,因为它考虑整个场景。移动到目标是局部和动态的,它仅考虑移动的方向和如何避免与其他代理碰撞。

可行走区域

在游戏场景中导航系统需要它自己的数据表示可行走区域。可行走区域表示在场景中代理可以停站或者移动的位置。在Unity中代理被描述成圆柱体。可行走区域是通过测试代理可以停站的位置域根据几何场景自动构建出来的。这些位置域组合成一个位于场景几何上方的表面,这个表面叫做导航网格。

导航网格以凸多边形的方式存储了表面的信息,凸多边形是非常有用的表现形式,因为我们知道在一个多边形中两点之间没有障碍物。加之多边形的边界我们用来存储相邻多边形的信息。这就允许我们响应整个可行走区域。

路径寻找

为了找到场景中两个位置域的路径,我们首先需要知晓开始点和目标点最近的多边形。然后我们开始从开始点搜寻,参观所有的导航点直到我们到达目标多边形。追踪参观了的多边形允许我们找到一个多边形序列,它会带领我们从起始点到目标点。寻找路径的一个通用算法是A*算法,这也是Unity使用的算法。

路径跟随

描述了从开始点到目标点路径的多边形序列叫做一个通道。代理会沿着通道的可视角方向到达目标点。如果你拥有一个简单的游戏里面只有一个代理在场景中移动,一次性找到通道的所有角并且使人物沿着连接角的直线运动是很好的。

当同时处理多个代理时,它们为了躲避彼此会与原来的初始道路出现偏差。使用包含直线短的路径尝试纠正这个偏差是非常困难并且很容易出错的。

因为每一帧代理移动的非常小,我们可以使用多边形的连接性修复通道,在这种情况下我们需要绕个弯子。然后我们快速找到下一个要朝向的可视角。

躲避障碍物

移动的逻辑是找到下一个角的位置并且以此为基础计算出到达目标的需要的方向和速度。使用期望的速度移动代理可导致与其他的代理碰撞。障碍回避在期望的移动速度和防止与其他代理和导航网格碰撞的速度之间平衡处一个新的速度。Unity使用RVO来预测和放置碰撞。

代理移动

最后当基于期望速度和障碍回避算出最后的速度时。在Unity中代理使用一个简单的动态模型模拟,同时也会将加速度考虑到内以便允许更加自然和平滑的移动。

在这一阶段是可以将代理的模拟速度转移到Mecanim动画系统来移动人物的,或者让导航系统区关心。

一旦代理使用了其中一个方法移动,模拟的代理被移动并被限制在导航网格内。最后一步对于一个强壮的导航来说是很重要的。

全局和局部

理解导航的重要一点就是区别全局导航和局部导航。

全局导航被用于找到整个世界的通道。找到一个全局导航的路径是一个很花费的操作,它需要许多电量和内容。

描述路径的多边形线性列表是一个灵活的数据结构,它可以根据代理的位置移动进行局部调整。局部导航尝试计算出最有效的移动到下一个角的路径而不与其他的代理或者移动的物体碰撞。

障碍物的两种情况

许多导航的应用程序要求其他类型的障碍物而不是其他代理。在一个射击游戏或者赛车游戏中对于木桶和子弹是非常有用的,这些障碍物可以使用局部障碍物回避处理或者全局路径查找。

当一个障碍物移动时,最好使用局部障碍物回避。这种方式代理可以提前回避障碍物。当障碍物变成静止时,可以被认为阻碍了所有代理的路径,障碍物可以影响全局导航的导航网格。

改变导航网格称为一个雕花。该处理进程检测障碍物的哪一部分接触到了导航网格然后在该处雕刻出一个洞。这是一个相当费计算的操作,另外它也是一个其他重要的原因,就是为什么使用碰撞回避处理移动障碍物。

局部碰撞回避也经常用于绕过少数散乱的障碍物。因为算法是局部的,它仅考虑下一个直接的碰撞体,并不能绕过陷阱或者处理路径上拥有障碍物的情况。这些情况可以使用雕花来解决。

断离网格连接的描述

导航网格多边形之间的连接使用路径寻找系统中的连接来描述。有时候让一个代理导航穿过非可行走区域是很重要的,例如,跳过一个篱笆或者通过一扇关闭的门。这种情况下需要知道行动的位置。

这行行动也可以使用断离网格连接取消,它告诉路径寻找者一条道路存在一个特殊的连接。该连接在随后的路径跟随中可以被访问到,特殊的行为也将被执行。

导航区域和成本

导航区域定义了穿过一个特殊的区域的难易程度,在路径寻找中更加偏向于低成本花费的区域。另外,每一个导航网格代理都有一个区域遮罩用于指定那块区域可以被移动。

在上面的例子中区域类型被用于两个常用情况:

通过指定水区域一个更高的成本使水区域具有更高的成本,用于处理在表层水走的更慢的场景。

门区域可以被指定的人物访问,创建创建出一个人类穿过门的场景,但是僵尸们却不能通过。

区域类型可以被指定给所有在导航网格烘焙中的物体,另外,每一个断离网格连接有一个属性用于指定区域类型。

路径寻找的代价

在一个狭窄的屋子内,成本代价可以允许你当寻找路径时控制路径寻找者更偏向于哪一块区域。例如,如果你设置区域的花费成为为3.0,穿越那片区域被认为花费的时长要比可替换路径长三倍。

为了完全理解成本花费是如何工作的,让我们看一下路径寻找者如何工作。

Unity使用A*算法计算在导航网格中的最短路径。A*算法在一个连接节点的图中工作。该算法从开始点的最接近节点开始然后访问相连接的节点知道到达目标节点。

因为Unity的导航网格表示是一个多边形网格,该网格是节点的位置。最短路径是在这些节点中计算出来。

上面图片中的黄点和直线展示了节点和连接是如何在导航网格中放置的,并且沿着A*算法的运动顺序。

两个节点的移动花费取决于运行距离,连接下多边形区域类型相关的花费为distance * cost。

在实践中这意味着,如果一个区域的cost为2.0,多边形之间的距离会表现出2倍的长度。A*算法要求所有的cost都必须大于1。

cost所代理的路径结果很难被改变,尤其对于长路径。使用costs最好的办法是将他们当成提示牌。例如,如果你想让代理不经常使用断离网格连接,你应该提高它们的cost。但是调整代理在路面行走的表现将很具有挑战性。

你在一些场景中可能发现路径寻找者并不总是选择最短的路径。原因就是节点的布局。这些效果可以在一大片自由区域中拥有一个很小的障碍物时被察觉到,它导致导航网格非常大但是多边形非常小。在这种情况下在大多边形下的节点可以在任何位置放置,从路径寻找者的角度看它们看起来像一个弯道。

每一个区域类型的花费可以在Areas Tabs标签页中全局设置,或者对每一个代理使用一个脚本覆盖它们。

区域类型

区域类型实在导航窗口中的Areas Tabs中指定的。这有29中自定义的类型,3中内置类型:Walkable,Not WalkAble, and Jump.

Walkable是一个通用的区域类型,它指定可行走的区域。

NotWalkable是一个通用的区域类型,它放置被导航。在你想标示某个物体为障碍物时非常有用,但是不要在它上面建设导航网格。

Jump是一块被指定自动产生断离网格连接的区域。

如果不通区域的几个物体重合,导航网格区域将使用具有最高的索引的类型。不过这里有一个例外:Not Walkable总是具有优先级。如果你想阻挡一块区域这是很有用的。

区域遮罩

每一个代理都有一个区域遮罩用于指明哪一个区域它可以导航。区域遮罩可以在代理属性中设置,或者在运行时使用脚本操作位掩码。

当你想让某一类型的人物通过一个区域时区域这招是非常有用的。例如,在一个躲避僵尸类的游戏中,你可以表示每一个门为Door区域类型,并取消僵尸人物区域遮罩中的Door区域选项。

使用累加载入载入多个导航网格

不同场景中的导航网格默认情况下是不连接的。当你使用Application.LoadLevelAdditive()载入另一个场景时你需要使用断离网格连接连接不同场景中的网格导航。

在这个例子中我们有场景1和场景2。场景1有一个断离网格导航连接可行走区域,场景2有一个断离网格导航连接可行走区域。必要时可以使用多个断离网格连接连接多个场景。

当授权场景的一个终点连接断离网格连接时未连接上,当一个新的场景载入时,断离网格连接会被重新连接。

如果多个场景在同一个区域内有多个网格导航,该位置可能会使用任意的导航网格。这会应用到代理,断离网格连接,和使用导航API的位置拾取。你应该交叉Off-Mesh Link创建场景,它们才会在一个导航网格中明确的开始和结束。重叠的导航区域不会被自动连接。

与其他组件组合使用网格导航代理

你可以与其他组件组合使用网格导航代理,网格导航障碍物,和断离网格连接。这有一个可以组合和不可以组合的组件列表。

网格导航代理组件和物体组件

你不可以为一个网格导航代理组件添加一个物理组件以相互避免。

就是说,导航系统模拟代理和它们对于障碍物和静态世界的反应。当然静态世界是 被烘焙过导航网格的。

如果你想让导航网格代理被物理物体驱使的话或者使用物理触发器:

添加一个Collider组件(如果没有的话)

添加一个Rigidbody组件

打开kinematic选项-非常重要

kinematic意味着刚体被除物理模拟外的其他东西控制。

如果导航网格代理组件和刚体组件(非运动学)同时激活的话,你就有了竞争条件。

两个组件同时想要移动代理最终导致一个不确定性的表现

你可以使用导航代理网格组件移动玩家人物而不是物理系统

设置玩家代理的avoidance priority为一个较小的数(更高的优先级),允许玩家挤 过人群。

导航网格代理组件和动画组件

导航网格代理组件和开启了Root Motion的动画组件可以引起条件竞争

两个组件都尝试每一帧移动Transform组件

两个可能的解决方案

信息应该总是流向一个方向

要么就是代理移动人物动画跟随要么就是动画移动人物

否则那你会很难有一个反馈循环

动画跟随代理

对于动画组件Animator使用NavMeshAgent.velocity作为一个输入粗略的模

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[150179],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。