Fix units considering terrain when entering other actors

This commit is contained in:
Gustas
2023-09-22 12:14:03 +03:00
committed by Matthias Mailänder
parent e0df59464e
commit b25146265d
2 changed files with 7 additions and 10 deletions

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Activities
case EnterState.Entering: case EnterState.Entering:
{ {
// Check that we reached the requested position // Check that we reached the requested position
var targetPos = target.Positions.ClosestToWithPathFrom(self); var targetPos = target.Positions.ClosestToIgnoringPath(self.CenterPosition);
if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor) if (!IsCanceling && self.CenterPosition == targetPos && target.Type == TargetType.Actor)
OnEnterComplete(self, target.Actor); OnEnterComplete(self, target.Actor);

View File

@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Target target; readonly Target target;
readonly Color? targetLineColor; readonly Color? targetLineColor;
readonly WDist targetMovementThreshold; readonly WDist targetMovementThreshold;
WPos? targetStartPos; WPos targetStartPos;
public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThreshold, Color? targetLineColor = null) public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
{ {
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Activities
protected override void OnFirstRun(Actor self) protected override void OnFirstRun(Actor self)
{ {
targetStartPos = target.Positions.ClosestToWithPathFrom(self); targetStartPos = target.Positions.ClosestToIgnoringPath(self.CenterPosition);
} }
public override bool Tick(Actor self) public override bool Tick(Actor self)
@@ -47,17 +47,14 @@ namespace OpenRA.Mods.Common.Activities
return false; return false;
var currentPos = self.CenterPosition; var currentPos = self.CenterPosition;
var targetPos = target.Positions.ClosestToWithPathFrom(self); var targetPos = target.Positions.ClosestToIgnoringPath(currentPos);
if (targetStartPos == null || targetPos == null)
return true;
// Give up if the target has moved too far // Give up if the target has moved too far
if (targetMovementThreshold > WDist.Zero && (targetPos.Value - targetStartPos.Value).LengthSquared > targetMovementThreshold.LengthSquared) if (targetMovementThreshold > WDist.Zero && (targetPos - targetStartPos).LengthSquared > targetMovementThreshold.LengthSquared)
return true; return true;
// Turn if required // Turn if required
var delta = targetPos.Value - currentPos; var delta = targetPos - currentPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : mobile.Facing; var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : mobile.Facing;
if (facing != mobile.Facing) if (facing != mobile.Facing)
{ {
@@ -69,7 +66,7 @@ namespace OpenRA.Mods.Common.Activities
var speed = mobile.MovementSpeedForCell(self.Location); var speed = mobile.MovementSpeedForCell(self.Location);
if (delta.LengthSquared <= speed * speed) if (delta.LengthSquared <= speed * speed)
{ {
mobile.SetCenterPosition(self, targetPos.Value); mobile.SetCenterPosition(self, targetPos);
return true; return true;
} }