在Unity中使用NavMesh导航

本文详细介绍了在Unity中使用NavMesh进行游戏导航和寻路的原理及实践。通过NavMesh,开发者可以创建出能智能移动的NPC,避开障碍物。文章讲解了NavMesh的不同组件,包括NavMesh、NavMesh Agent、Off-Mesh Link和NavMesh Obstacle。通过实例展示了如何设置和烘焙NavMesh,以及如何使玩家对象在迷宫中自动移动。文章强调了NavMesh在运行时的灵活性和在过程生成级别中的应用,并提醒读者注意烘焙的资源消耗问题。
摘要由CSDN通过智能技术生成

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

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障碍物组件使您能够描述代理商在导航世界时应避免的移动障碍物。 由物理系统控制的桶或板条箱是障碍的一个很好的例子。 尽管障碍物正在移动,特工们会尽力避免它,但是一旦障碍物静止,它将在导航网格

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值