第一波果岭向右(到达第一个航路点),但在延长隧道后,第二波果岭就是为什么你会失去第一个航路点而直接前往第二个航路点。(为什么这是一种迂回的方式)
对不起,我的英语不好。
第一波果岭向右(到达第一个航路点),但在延长隧道后,第二波果岭就是为什么你会失去第一个航路点而直接前往第二个航路点。(为什么这是一种迂回的方式)
实际上有两个问题:1)如何修复第一个航点 2)为什么去第二个航点这么奇怪
这是敌人遍历航路点的代码。
using System;
using UnityEngine;
using UnityEngine.AI;
[RequireComponent(typeof(NavMeshAgent))]
public class EnemyMovement : MonoBehaviour
{
[SerializeField] public Transform[] points;
[SerializeField] private int destPoint = 0;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
agent.autoBraking = false;
agent.destination = points[destPoint].position;
}
void GotoNextPoint()
{
if(destPoint != points.Length)
{
agent.destination = points[destPoint].position;
}
}
void Update()
{
if(agent.remainingDistance < 0.5f)
{
destPoint++;
GotoNextPoint();
}
}
private void OnDrawGizmos()
{
Gizmos.DrawLine(gameObject.transform.position, points[destPoint].position);
}
}