物体卡在了Navmesh表面的边缘上

时间:2019-07-13 18:32:57

标签: c# unity3d navmesh

The resulting image 因此,我在统一3D平面上制作了Navmesh曲面。立方体将不断产生圆柱体,以使其移向球体。但是生成的圆柱体继续尝试在Navmesh表面的边缘移动,结果卡住了。

我尝试更改飞机的尺寸,但没有任何改变。我认为生成路径可能有问题,但我不知道它是什么。

这些是产生代码。

public class EnemySpawner : MonoBehaviour
{
    public GameObject enemy;               
    public float SpawnTime = 2f;
    public Transform[] spawnPoints;


    void Start()
    {
        InvokeRepeating("Spawn", SpawnTime, SpawnTime);
    }

    void Spawn()
    {
        int spawnPointIndex = Random.Range(0, spawnPoints.Length);

        Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
}

这些是Nav代理的代码

public class EnemyController : MonoBehaviour
{
    public Transform player;
    private UnityEngine.AI.NavMeshAgent agent;

    // Start is called before the first frame update
    void Start()
    {
        agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
        agent.destination = player.position;
    }
}

我希望它直接向球体移动,但实际上是在尝试沿NavMesh曲面的边缘移动。

0 个答案:

没有答案
相关问题