unity3d - NavMeshAgent.SetDestination Y轴问题
问题描述
我正在尝试为 GameObjects 创建简单的运动 AI。
每个游戏对象都有NavMeshAgent
Vector3 destination = new Vector3(Random.Range(-walkArea, walkArea), 0, Random.Range(-walkArea, walkArea));
navAgent.SetDestination(destination);
这就是我想要做的。但是我烤的地面不平坦,Y轴可能高达30-40。
因此,如果 GameObject 周围有山,他就会被卡住而无法翻越。
我能做些什么呢?如果我只是navAgent.Move(destination)
,一切正常。游戏对象在 XZ 位置传送而不用担心 Y 轴。
我怎么能做同样的事情SetDestination
?
解决方案
我找到了解决方案。
GameObject
我主要empty gameobject
用NavMeshAgent
.
Vector3 destination = new Vector3(Random.Range(-walkArea, walkArea), 0, Random.Range(-walkArea, walkArea));
navDestinationObject.Move(destination);
navAgent.destination = navDestinationObject.transform.position;
navDestinationObject
在 上获得正确的 Y 轴.Move
,然后我们只需将 main 移动GameObject
到navDestinationObject
位置。
但我认为必须有更好的解决方案......
推荐阅读
- javascript - localStorage 在其他主机中不起作用 - javascript
- c# - 如何在 Web 控件中包含 html 元素,例如 C# 中的 TableCell
- node.js - 电子功能窗口全部关闭看不到其他功能
- asp.net - ASP.NET Web 应用程序需要 3 小时来构建和发布
- c# - 系统线程任务字符串到字符串转换错误
- mysql - 大量列,全选需要永远
- pandas - 如何计算数据透视表中的总方差
- c# - 有没有办法在不使用 codesmith 的情况下向 NetTiers 模型添加新列?
- php - 如何使用 mod-rewrite 相应地重定向 API 调用和 Web 应用程序调用
- google-play - 为什么我的应用程序更新在 Google Play 商店中被拒绝,尽管我提交了多次需要的测试登录?