Core/PathFinding: Fix GetPathPolyByPosition() using only 2D distance instead of 3D

Signed-off-by: jackpoz <giacomopoz@gmail.com>
This commit is contained in:
xvwyh
2020-09-19 21:35:40 +02:00
committed by Ovahlord
parent f067228bd7
commit 6342b0def2

View File

@@ -98,8 +98,7 @@ dtPolyRef PathGenerator::GetPathPolyByPosition(dtPolyRef const* polyPath, uint32
return INVALID_POLYREF;
dtPolyRef nearestPoly = INVALID_POLYREF;
float minDist2d = FLT_MAX;
float minDist3d = 0.0f;
float minDist = FLT_MAX;
for (uint32 i = 0; i < polyPathSize; ++i)
{
@@ -107,22 +106,21 @@ dtPolyRef PathGenerator::GetPathPolyByPosition(dtPolyRef const* polyPath, uint32
if (dtStatusFailed(_navMeshQuery->closestPointOnPoly(polyPath[i], point, closestPoint, nullptr)))
continue;
float d = dtVdist2DSqr(point, closestPoint);
if (d < minDist2d)
float d = dtVdistSqr(point, closestPoint);
if (d < minDist)
{
minDist2d = d;
minDist = d;
nearestPoly = polyPath[i];
minDist3d = dtVdistSqr(point, closestPoint);
}
if (minDist2d < 1.0f) // shortcut out - close enough for us
if (minDist < 1.0f) // shortcut out - close enough for us
break;
}
if (distance)
*distance = dtMathSqrtf(minDist3d);
*distance = dtMathSqrtf(minDist);
return (minDist2d < 3.0f) ? nearestPoly : INVALID_POLYREF;
return (minDist < 3.0f) ? nearestPoly : INVALID_POLYREF;
}
dtPolyRef PathGenerator::GetPolyByLocation(float const* point, float* distance) const