我正在使用NavMesh寻路解决方案进行AI,我不想使用NavMeshAgent,因为有一些限制(比如雕刻物体接近时传送等),
因此我做了一种融合,在NavMesh.CalculatePath()的路径上移动了一个Rigidbody,这到目前为止工作得很好,但我在路径上检测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]);
}
}
提前致谢:)