Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix units considering terrain when entering other actors #21071

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/Enter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public override bool Tick(Actor self)
case EnterState.Entering:
{
// 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)
OnEnterComplete(self, target.Actor);

Expand Down
15 changes: 6 additions & 9 deletions OpenRA.Mods.Common/Activities/Move/LocalMoveIntoTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class LocalMoveIntoTarget : Activity
readonly Target target;
readonly Color? targetLineColor;
readonly WDist targetMovementThreshold;
WPos? targetStartPos;
WPos targetStartPos;

public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThreshold, Color? targetLineColor = null)
{
Expand All @@ -35,7 +35,7 @@ public LocalMoveIntoTarget(Actor self, in Target target, WDist targetMovementThr

protected override void OnFirstRun(Actor self)
{
targetStartPos = target.Positions.ClosestToWithPathFrom(self);
targetStartPos = target.Positions.ClosestToIgnoringPath(self.CenterPosition);
}

public override bool Tick(Actor self)
Expand All @@ -47,17 +47,14 @@ public override bool Tick(Actor self)
return false;

var currentPos = self.CenterPosition;
var targetPos = target.Positions.ClosestToWithPathFrom(self);

if (targetStartPos == null || targetPos == null)
return true;
var targetPos = target.Positions.ClosestToIgnoringPath(currentPos);

// 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;

// Turn if required
var delta = targetPos.Value - currentPos;
var delta = targetPos - currentPos;
var facing = delta.HorizontalLengthSquared != 0 ? delta.Yaw : mobile.Facing;
if (facing != mobile.Facing)
{
Expand All @@ -69,7 +66,7 @@ public override bool Tick(Actor self)
var speed = mobile.MovementSpeedForCell(self.Location);
if (delta.LengthSquared <= speed * speed)
{
mobile.SetCenterPosition(self, targetPos.Value);
mobile.SetCenterPosition(self, targetPos);
return true;
}

Expand Down