首页 > 解决方案 > 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

标签: unity3d

解决方案


我找到了解决方案。

GameObject我主要empty gameobjectNavMeshAgent.

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 移动GameObjectnavDestinationObject位置。

但我认为必须有更好的解决方案......


推荐阅读