Core/Objects: further improvements for MovePositionToFirstCollision

Port From (https://github.com/TrinityCore/TrinityCore/commit/26e7da1622b217f66d28771836014ca9023efd16)
This commit is contained in:
hondacrx
2022-02-18 17:27:32 -05:00
parent cb68969f1d
commit e6b9631ed0
2 changed files with 60 additions and 10 deletions
+24 -2
View File
@@ -3425,15 +3425,37 @@ namespace Game.Entities
// Use a detour raycast to get our first collision point
PathGenerator path = new(this);
path.CalculatePath(destx, desty, destz, false, true);
// We have a invalid path result. Skip further processing.
if ((path.GetPathType() & ~(PathType.Normal | PathType.Shortcut | PathType.Incomplete | PathType.FarFromPoly)) != 0)
return;
Vector3 result = path.GetPath()[path.GetPath().Length - 1];
destx = result.X;
desty = result.Y;
destz = result.Z;
UpdateAllowedPositionZ(destx, desty, ref destz);
// Object is using a shortcut. Check static LOS
float halfHeight = GetCollisionHeight() * 0.5f;
if (path.GetPathType().HasFlag(PathType.Shortcut))
{
bool vmapCol = Global.VMapMgr.GetObjectHitPos(PhasingHandler.GetTerrainMapId(GetPhaseShift(), GetMap(), pos.posX, pos.posY),
pos.posX, pos.posY, pos.posZ + halfHeight,
destx, desty, destz + halfHeight,
out destx, out desty, out destz, -0.5f);
destz -= halfHeight;
// Collided with static LOS object, move back to collision point
if (vmapCol)
{
destx -= SharedConst.ContactDistance * MathF.Cos(angle);
desty -= SharedConst.ContactDistance * MathF.Sin(angle);
dist = MathF.Sqrt((pos.posX - destx) * (pos.posX - destx) + (pos.posY - desty) * (pos.posY - desty));
}
}
// check dynamic collision
float halfHeight = GetCollisionHeight() * 0.5f;
bool col = GetMap().GetObjectHitPos(GetPhaseShift(), pos.posX, pos.posY, pos.posZ + halfHeight, destx, desty, destz + halfHeight, out destx, out desty, out destz, -0.5f);
destz -= halfHeight;