Unity3d NavMesh 工作异常,不明白为什么

Unity3d NavMesh is working strange, can't understand why

The first wave of green goes right (to the first waypoint), but after lengthening the tunnel, the second wave is why green you lose the first waypoint and go straight to the second. (And why is that somehow a roundabout way)

抱歉我的英语不好。

第一波绿色向右(到第一个路标),但是在加长隧道后,第二波是为什么绿色你失去了第一个路标并直奔第二个路标。 (为什么这是一种迂回的方式)

其实有两个问题: 1)如何固定第一个航路点 2) 为什么去第二个航路点这么奇怪

这里是敌人要遍历的代码waypoints.

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);
    }
}

确定是NavMesh做的大tile(NavMeshBuildSettings.tileSize),但是改不了,因为用了别人的作品(https://github.com/Unity-Technologies/NavMeshComponents/tree/mast... mples / Scripts)。所以事实证明,要更改运行时 navMesh,您不仅必须在网格更改代码中注册,还必须编写行 (.overrideTileSize = true;)

var defaultBuildSettings = NavMesh.GetSettingsByID (0).overrideTileSize = true;

之后我可以更改图块的大小,并且停止了错误路径的选择。