diff options
author | xvwyh <xvwyh@users.noreply.github.com> | 2020-09-19 21:35:40 +0200 |
---|---|---|
committer | jackpoz <giacomopoz@gmail.com> | 2020-09-19 21:35:40 +0200 |
commit | 2d6237f06ae6b74bb8ebfe745d8c0f1ce440e2fe (patch) | |
tree | 17d0d29ef473741f7898406f3948389c649a2834 /src | |
parent | 5491cb51a25b6e3c465e97b3c57ba67a8ea0bcce (diff) |
Core/PathFinding: Fix GetPathPolyByPosition() using only 2D distance instead of 3D
Signed-off-by: jackpoz <giacomopoz@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Movement/PathGenerator.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp index e568a86408a..04d047fc008 100644 --- a/src/server/game/Movement/PathGenerator.cpp +++ b/src/server/game/Movement/PathGenerator.cpp @@ -96,8 +96,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) { @@ -105,22 +104,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 |