aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorxvwyh <xvwyh@users.noreply.github.com>2020-09-19 21:35:40 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-27 20:08:41 +0100
commit1a073e2df05c8ded3ce8afc89eaf29c7f5d506ce (patch)
treeea801c2c8d13a1b3cecaf1c724708abda16f3cc5 /src
parentd06c93185ae209e8f355c17ef2de21f9976c7b52 (diff)
Core/PathFinding: Fix GetPathPolyByPosition() using only 2D distance instead of 3D
Signed-off-by: jackpoz <giacomopoz@gmail.com> (cherry picked from commit 2d6237f06ae6b74bb8ebfe745d8c0f1ce440e2fe)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Movement/PathGenerator.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp
index c22d1280e24..8519649bdf4 100644
--- a/src/server/game/Movement/PathGenerator.cpp
+++ b/src/server/game/Movement/PathGenerator.cpp
@@ -97,8 +97,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)
{
@@ -106,22 +105,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