Core/Objects: improve MovePositionToFirstCollision results
This commit is contained in:
1 parent
c5c99f1eea
commit
a3662d9a74
1 file changed
+27
-38
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user