如何在 Navmesh 中将玩家从一个网格移动到另一个网格

How to move player from one mesh to another in the Navmesh

我试图让我的玩家从在另一个网格中激活的触发器传送到网格中的一个点,更具体地说是在天花板中。我尝试了这个,但它让我把玩家留在了他已经所在的网格的一角。

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Player"))

    {
        _playerPrefab.transform.position = _initialposition.transform.position;
    }
}

尝试使用 NavMesh 代理提供的扭曲功能:

_playerPrefab.GetComponent<NavMeshAgent>().Warp(_initialposition.transform.position)

如果您想使用 NavMesh API,您的播放器需要有一个 NavMeshAgent。

然后你可以直接调用yourAgent.SetDestination(yourDestination)

最后我通过 tranform.position 改变位置,禁用 navMesh Agent 并将速度设置为零来解决这个问题。