mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 09:17:36 +01:00
Core/PathFinding: Fix GetPathPolyByPosition() using only 2D distance instead of 3D
Signed-off-by: jackpoz <giacomopoz@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user