Core/Objects: MovePositionToFirstCollision will now always use detour raycasts to get the first collision point

This commit is contained in:
Ovahlord
2020-02-20 21:49:18 +01:00
parent a378f23d80
commit 4bc9c07407

View File

@@ -2575,34 +2575,10 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float
dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty));
}
if (Unit const* unit = ToUnit())
{
PathGenerator path(unit);
path.CalculatePath(destx, desty, destz, false, true);
pos.Relocate(Vector3ToPosition(path.GetPath().back()));
}
else
{
// To-do: move non-unit cases to detour raycasts as well
float step = dist / 10.0f;
for (uint8 j = 0; j < 10; ++j)
{
// do not allow too big z changes
if (std::fabs(pos.m_positionZ - destz) > 6.0f)
{
destx -= step * std::cos(angle);
desty -= step * std::sin(angle);
UpdateAllowedPositionZ(destx, desty, destz);
}
// we have correct destz now
else
{
pos.Relocate(destx, desty, destz);
break;
}
}
}
// Use a detour raycast to get our first collision point
PathGenerator path(this);
path.CalculatePath(destx, desty, destz, false, true);
pos.Relocate(Vector3ToPosition(path.GetPath().back()));
float groundZ = VMAP_INVALID_HEIGHT_VALUE;
Trinity::NormalizeMapCoord(pos.m_positionX);