【发布时间】:2020-04-21 01:56:52
【问题描述】:
所以我有一个胶囊作为我的 NavMeshAgent(现在),它跟随玩家并避开墙壁,但是当玩家与胶囊碰撞时,胶囊开始随机游走。我的 NavMeshAgent 代码如下:[SerializeField] 转换目的地;
NavMeshAgent navMeshAgent;
// Start is called before the first frame update
void FixedUpdate()
{
navMeshAgent = this.GetComponent<NavMeshAgent>();
if (navMeshAgent == null)
{
Debug.LogError("The nav mesh agent component is not attached to " + gameObject.name);
}
else if (navMeshAgent.enabled == true)
{
SetDestination();
}
}
private void SetDestination()
{
if (destination != null)
{
Vector3 targetVector = destination.transform.position;
navMeshAgent.SetDestination(targetVector);
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
SetDestination();
}
}
非常感谢任何帮助:)
【问题讨论】:
标签: c# unity3d artificial-intelligence