In this tutorial we will learn about Navmesh in Unity, how to create it and use it on your game as part of navigation.
在本教程中,我们将学习有关Unity中Navmesh的知识,以及如何在导航中创建和使用它的方法。
Unity中的导航和寻路 (Navigation and Pathfinding in Unity)
Have you ever wondered how the various NPCs (Non-Playable Characters) in a game move around the game world, avoiding objects and even sometimes avoiding you, only to pop out from behind you to give you a jump scare. How is this done so realistically? How do these so called bots decide which paths they should take and which to avoid?
您是否曾经想过,游戏中的各种NPC(不可玩角色)如何在游戏世界中移动,避开物体,甚至有时避开您,而只是从您的身后突然冒出来,给您带来跳跃的恐惧。 如何现实地做到这一点? 这些所谓的漫游器如何决定应采取的路径以及应避免的路径?
In Unity, this miracle (not so much once you know how it works) is achieved using NavMeshes.
在Unity中,使用NavMeshes可以实现这个奇迹(一旦您知道它是如何运作的,就不那么多了)。
NavMeshes or Navigational Meshes are a part of the Navigation and path finding system of Unity. The navigation system allows you to create characters that can intelligently move around the game world, using navigation meshes that are created automatically from your Scene geometry. Dynamic obstacles allow you to alter the navigation of the characters at runtime, while off-mesh links let you build specific actions like opening doors or jumping down from a ledge.
NavMeshes或导航网格是统一导航和寻路系统的一部分。 导航系统允许您使用从“ 场景”几何体自动创建的导航网格来创建可以在游戏世界中智能移动的角色。 动态障碍物使您可以在运行时更改角色的导航,而离网链接则使您可以建立特定的动作,例如开门或从窗台跳下。
![Navigation Using Mash](https://i-blog.csdnimg.cn/blog_migrate/57e7f79e854705dc20cccbc9d74a1114.png)
NavMesh的不同组件 (Different Components of NavMesh)
The Unity NavMesh system consists of the following pieces:
Unity NavMesh系统由以下部分组成:
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 (导航网格的缩写)是一种数据结构,用于描述游戏世界的可行走表面,并允许查找游戏世界中从一个可行走位置到另一个位置的路径。 数据结构是根据关卡几何自动生成或烘焙的。
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.
NavMesh Agent组件可帮助您创建在朝目标前进时彼此避开的角色。 代理商使用NavMesh来推理游戏世界,他们知道如何避免彼此以及移动障碍物。
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.
NavMesh障碍物组件使您能够描述代理商在导航世界时应避免的移动障碍物。 由物理系统控制的桶或板条箱是障碍的一个很好的例子。 尽管障碍物正在移动,特工们会尽力避免它,但是一旦障碍物静止,它将在导航网格