Core/Objects: use detour raycasts for unit based MovePositionToFirstCollision calls

This commit is contained in:
Ovahlord
2020-02-08 23:33:02 +01:00
parent c3d2b2c6d5
commit e0a1c5fa1a

View File

@@ -24,6 +24,7 @@
#include "Common.h"
#include "Creature.h"
#include "DynamicTree.h"
#include "G3DPosition.hpp"
#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
@@ -37,6 +38,7 @@
#include "Opcodes.h"
#include "OutdoorPvPMgr.h"
#include "PhasingHandler.h"
#include "PathGenerator.h"
#include "Player.h"
#include "SharedDefines.h"
#include "SpellAuraEffects.h"
@@ -2573,22 +2575,32 @@ 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));
}
float step = dist / 10.0f;
for (uint8 j = 0; j < 10; ++j)
if (Unit const* unit = ToUnit())
{
// do not allow too big z changes
if (std::fabs(pos.m_positionZ - destz) > 6.0f)
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)
{
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;
// 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;
}
}
}