diff options
| author | Ovah <dreadkiller@gmx.de> | 2020-05-01 13:43:24 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2022-01-01 23:30:48 +0100 |
| commit | 26e7da1622b217f66d28771836014ca9023efd16 (patch) | |
| tree | 6b0787286ac4f2127febb8dafc49f407c3fd0655 /src/server/game/Entities/Object | |
| parent | 99aef26563c689bdf4f334bfc27b442c6730eabc (diff) | |
Core/Objects: further improvements for MovePositionToFirstCollision (#24523)
* Core/Objects: further improvements for MovePositionToFirstCollision
* the PathGenerator will now normalize incomplete destinations as well
* normalize destination positions before launching detour raycasts to get better direction data
* exclude unwanted pathfinding results from further use to avoid unintended behaivior
* Core/PathFinding: Split PATHFIND_FARFROMPOLY into PATHFIND_FARFROMPOLY_START and PATHFIND_FARFROMPOLY_END for start and end position
Handle PATHFIND_FARFROMPOLY_END as valid in MovePositionToFirstCollision
Co-authored-by: jackpoz <giacomopoz@gmail.com>
(cherry picked from commit 6485422c6127262855b3c90183388e29dc251de5)
Diffstat (limited to 'src/server/game/Entities/Object')
| -rw-r--r-- | src/server/game/Entities/Object/Object.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 484631d902d..6ae346f26de 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -3212,16 +3212,37 @@ void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float // Use a detour raycast to get our first collision point PathGenerator path(this); path.CalculatePath(destx, desty, destz, false, true); + + // We have a invalid path result. Skip further processing. + if (path.GetPathType() & ~(PATHFIND_NORMAL | PATHFIND_SHORTCUT | PATHFIND_INCOMPLETE | PATHFIND_FARFROMPOLY_END)) + return; + G3D::Vector3 result = path.GetPath().back(); destx = result.x; desty = result.y; destz = result.z; - UpdateAllowedPositionZ(destx, desty, destz); + // Object is using a shortcut. Check static LOS + float halfHeight = GetCollisionHeight() * 0.5f; + if (path.GetPathType() & PATHFIND_SHORTCUT) + { + bool col = VMAP::VMapFactory::createOrGetVMapManager()->getObjectHitPos(PhasingHandler::GetTerrainMapId(GetPhaseShift(), GetMap(), pos.m_positionX, pos.m_positionY), + pos.m_positionX, pos.m_positionY, pos.m_positionZ + halfHeight, + destx, desty, destz + halfHeight, + destx, desty, destz, -0.5f); + + destz -= halfHeight; + // Collided with static LOS object, 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)); + } + } // 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, |
