This commit is contained in:
David Markowitz
2023-08-09 00:34:39 -07:00
parent fc56777969
commit 5f7a108154
5 changed files with 41 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ dNavMesh::dNavMesh(uint32_t zoneId) {
dNavMesh::~dNavMesh() {
// Clean up Recast information
if(m_Solid) rcFreeHeightField(m_Solid);
if (m_Solid) rcFreeHeightField(m_Solid);
if (m_CHF) rcFreeCompactHeightfield(m_CHF);
if (m_CSet) rcFreeContourSet(m_CSet);
if (m_PMesh) rcFreePolyMesh(m_PMesh);
@@ -135,17 +135,19 @@ float dNavMesh::GetHeightAtPoint(const NiPoint3& location, const float halfExten
float nearestPoint[3] = { 0.0f, 0.0f, 0.0f };
dtQueryFilter filter{};
auto res = m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, nearestPoint);
res = m_NavQuery->getPolyHeight(nearestRef, pos, &toReturn);
auto hasPoly = m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, nearestPoint);
m_NavQuery->getPolyHeight(nearestRef, pos, &toReturn);
if (toReturn != 0.0f) {
DluAssert(toReturn == nearestPoint[1]);
}
if (toReturn == 0.0f) {
toReturn = location.y;
// If we were unable to get the poly height, but the query returned a success, just use the height of the nearest point.
// This is what seems to happen anyways and it is better than returning zero.
} else if (res == DT_SUCCESS) {
toReturn = nearestPoint[1];
// If we were unable to get the poly height, but the query returned a success, just use the height of the nearest point.
// This is what seems to happen anyways and it is better than returning zero.
if (hasPoly == DT_SUCCESS) {
toReturn = nearestPoint[1];
} else {
toReturn = location.y;
}
}
// If we failed to even find a poly, do not change the height since we have no idea what it should be.