Unity【Tutorial——Beginner——Unity NavMesh】

Unity个人学习笔记,资料来源unity官网

官网

全名navigation mesh导航网格,查找一下出现了很多,先学习找到的这个教程好了,起码先明白是什么东西
貌似UI里也有这个记得

Learn how to create AI pathfinding using the Unity NavMesh components!
居然事用来给AI寻找路径的吗

老样子遇到新名词往往可以查找手册NavMesh手册
Mesh手册

先简单说,mesh直译:网格,texture纹理 , material材料 shader着色器

知乎的有关文章
把版本换到2019的lts
下载链接

在这里插入图片描述

**

1.Basics

**

按照手册里NavMesh的做了,反正直接用3D物体做了点平面,和墙,但是并没有什么反应,老实跟着视频做喽

那么开始了,首先搞一个cube作为ground,然后再弄点walls ,Now the improved high level NavMesh components are available now.(高级?)The first thing that we want to do is, bake a NavMesh.(烘焙又是一个大坑。先记着NavMesh是要烘焙的就行).

This means that we will define what surfaces are walkable for our agent.(在讲一个新的概念的时候,最好就是说明它到底是干嘛的,有什么作用,好记!)
然后搞一个空物体,rename it to NavMesh.
So this game object is going to be responsible for baking our NavMesh(所以这个游戏对象将负责烘焙我们的NavMesh), 给它添加NavMesh surface component,版本太旧了吗,我们没有这个组件了。。 组件手册
查找可知它默认是没有的。要去git hub上下载
手册

不知道怎么操作。。幸好它下面有一个叫How to get start的说明,观察可以发现视频里确实也比我们多了一个叫NavMeshComponents的文件夹,然后,感谢面向搜索引擎的编程,不会的一定要搜索,干楞着无济于事只会浪费时间

在这里插入图片描述
在这里插入图片描述

看到右下加那个 Auto Generate Lighting On了吗,点击它,没错可以点,又不花钱点点不会死

在这里插入图片描述

勾选那个Auto Generate,虽然我都不知道是什么时候关掉的,但是这样就会自动渲染了,不会出现奇怪的事情,感谢群里的大佬指点,不懂就去问,想方设法,这种东西想破头也不可能知道啊

反正成功把Nav Mesh的文件加进来了,现在我们有这个组件了,不过这个还要跟着版本升级,,幸好操作也不麻烦

所以为什么点了Bake没有反应?

我真的是tm的服气了,为什么点了一下Gizmo就出来了???什么鬼啊丢你老母

反正出来了就好,以后也学会了要到处乱点
在这里插入图片描述

这些黑线和灰色区域又是什么呢

the NavMesh currently treats our player himself as an obstacle. To avoid this , we edit the include layers. we want to include when baking our NavMesh. In our case , we don’t want to include out player,
简单来说就是给player一个层,然后不选这个层就完事了

We can also choose whether we want to bake on NavMesh from the Renderer meshes, meaning the actual look of our level or using physics colliders.

就是说如果选了physics colliders,只会给添加了collider的物体加

在这里插入图片描述

如果打开Agent Type 里的open agent settings会跳转到Navigation窗口,
But if we go ahead and hit the plus sign, we can create another one. This one is going to be an Ogre, 如果你改变这个代理人的体型,那么它可以去的地方也会发生改变

在这里插入图片描述

Now we don’t want our walls to be walkable. So to change this, we can go and select our walls and here we’ll add another component called the NavMesh modifier.
The NavMesh modifier, allows us to change NavMesh settings for a given object.
可以把墙都放在一个空物体下面,然后把组件给空物体,

如果勾选ignore from build(从生成中忽略),it’s just going to completely ignore our walls.如果把墙的层设为player也能达到相同的效果(不过两者都不用)
Instead use override area. This allows us to change the area type for this object.

在这里插入图片描述

有三种默认的area types, 没错选择not walkable, Our player can now only walk on the ground.

Finally , we can choose what agents this is going to affect. By default , this is set to all , but we can be specific. This allows us to create areas of the map, that are different for each agent. Say if you’re creating an RTS game and you don’t want your regular units to pass through fire, but you want your fire elementals to freely walk past it.

说不想让普通单位通过火焰,但是火元素可以走过去

So affected agents can actually be really useful.

接下来是有趣的让人物移动,
添加一个叫NavMesh Agent的组件, A Nav Mesh Agent is a character that can navigate around the mesh. 先不管它的一大堆设置,先搞一个简单控制的脚本
起名Player Controller.

So controlling a NavMesh Agent in Unity, Most of the time , we use a simple fucntion called SetDestination. This allows us to input some kind of position and our agent will then automatically find the shortest path there.

痛苦,不想看手册一大堆,但是NavMeshAgent
在这里插入图片描述

In our case, we have a level and on top of that level, we have a player. We also have a camera that looks at our level. And we want to be able to click on some part of the level and then have our player automatically move to that location.

在这里插入图片描述

To do that , we’ll look for some kind of mouse input.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值