1

我正在使用 NavMesh 寻路解决方案进行 AI,由于某些限制(例如当雕刻对象靠近时传送等),我不想使用 NavMeshAgent,

因此,我做了一种融合,在 NavMesh.CalculatePath() 的路径上移动刚体,到目前为止效果很好,但我无法检测到路径上的 OffMeshLinks(因为它只是 Vector3 的数组)。

我可以像上面那样使用 NavMesh.Raycast() 来“欺骗”一点,但它并不是一直都在工作,有时会检测到不是一个的 OffMeshLinks

NavMeshHit hit;
//Raycast between two corners of a path, because OffMeshLink are most of the time over a hole
if (NavMesh.Raycast(_pathCorners[0], _pathCorners[1], out hit, NavMesh.AllAreas))
{
    //If the hit position is really close to the corner, it's surely a offmeshlink generate from the NavMesh
    //Or if the second corner is higher than the first one, it's surely a offmeshlink I generate myself
    if ((hit.position - _pathCorners[0]).sqrMagnitude < 1 
        || _pathCorners[0].y < _pathCorners[1].y)
    {
        ActivateJump(_pathCorners[0], _pathCorners[1]);
    }
}

提前致谢 :)

4

0 回答 0