From a3662d9a74fa6f51b8479fe8cbd7db02e7bef833 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Wed, 29 Apr 2020 23:56:47 +0200 Subject: [PATCH] Core/Objects: improve MovePositionToFirstCollision results --- src/server/game/Entities/Object/Object.cpp | 65 +++++++++------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 892e215904..45c72c3964 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -2550,52 +2550,41 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float return; } - float halfHeight = GetCollisionHeight() * 0.5f; - UpdateAllowedPositionZ(destx, desty, destz); - - uint32 terrainMapId = PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY); - bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(terrainMapId, - pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, - destx, desty, destz + halfHeight, - destx, desty, destz, -0.5f); - - destz -= halfHeight; - - // collision occured - if (col) - { - // move back a bit - destx -= CONTACT_DISTANCE * std::cos(angle); - desty -= CONTACT_DISTANCE * std::sin(angle); - dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); - } - - // check dynamic collision - col = GetMap()->getObjectHitPos(GetPhaseShift(), - pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, - destx, desty, destz + halfHeight, - destx, desty, destz, -0.5f); - - destz -= halfHeight; - - // Collided with a gameobject - if (col) - { - destx -= CONTACT_DISTANCE * std::cos(angle); - desty -= CONTACT_DISTANCE * std::sin(angle); - dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty)*(pos.m_positionY - desty)); - } - // 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())); + G3D::Vector3 result = path.GetPath().back(); + destx = result.x; + desty = result.y; + destz = result.z; + + UpdateAllowedPositionZ(destx, desty, destz); + + + // check dynamic collision + float halfHeight = GetCollisionHeight() * 0.5f; + bool col = GetMap()->getObjectHitPos(GetPhaseShift(), + pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, + destx, desty, destz + halfHeight, + destx, desty, destz, -0.5f); + + destz -= halfHeight; + + // Collided with a gameobject, move back to collision point + if (col) + { + destx -= CONTACT_DISTANCE * std::cos(angle); + desty -= CONTACT_DISTANCE * std::sin(angle); + dist = std::sqrt((pos.m_positionX - destx)*(pos.m_positionX - destx) + (pos.m_positionY - desty) * (pos.m_positionY - desty)); + } float groundZ = VMAP_INVALID_HEIGHT_VALUE; Trinity::NormalizeMapCoord(pos.m_positionX); Trinity::NormalizeMapCoord(pos.m_positionY); - UpdateAllowedPositionZ(destx, desty, pos.m_positionZ, &groundZ); + UpdateAllowedPositionZ(destx, desty, destz, &groundZ); + pos.SetOrientation(GetOrientation()); + pos.Relocate(destx, desty, destz); // position has no ground under it (or is too far away) if (groundZ <= INVALID_HEIGHT)