0

第一波果岭向右(到达第一个航路点),但在延长隧道后,第二波果岭就是为什么你会失去第一个航路点而直接前往第二个航路点。(为什么这是一种迂回的方式)

对不起,我的英语不好。

第一波果岭向右(到达第一个航路点),但在延长隧道后,第二波果岭就是为什么你会失去第一个航路点而直接前往第二个航路点。(为什么这是一种迂回的方式)

实际上有两个问题: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);
    }
}
4

1 回答 1

0

确定问题是 NavMesh 制作大图块(NavMeshBuildSettings.tileSize),但我无法更改它,因为我使用了别人的工作(https://github.com/Unity-Technologies/NavMeshComponents/tree/mast ... mples / 脚本)。所以事实证明,要更改运行时navMesh,您不仅要在网格更改代码中注册,而且要编写该行(.overrideTileSize = true;

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

之后,我能够更改瓷砖的大小,并且停止选择错误的路径。

于 2019-01-24T04:04:00.580 回答