From 1fe988adc2b3e8774cef7f9401d9ea6bfab32673 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 31 Jul 2022 10:37:55 -0400 Subject: [PATCH] Fixed unit movement overshoot --- core/src/mindustry/ai/types/CommandAI.java | 2 +- core/src/mindustry/entities/units/AIController.java | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index 7e58a6c56d..cf0a2791d3 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -127,7 +127,7 @@ public class CommandAI extends AIController{ attackTarget != null && unit.within(attackTarget, engageRange) ? engageRange : unit.isGrounded() ? 0f : attackTarget != null ? engageRange : - 0f, unit.isFlying() ? 40f : 100f, false, null); + 0f, unit.isFlying() ? 40f : 100f, false, null, true); } //calculateFlock().limit(unit.speed() * flockMult) diff --git a/core/src/mindustry/entities/units/AIController.java b/core/src/mindustry/entities/units/AIController.java index c450ea6e27..bbdd2870b1 100644 --- a/core/src/mindustry/entities/units/AIController.java +++ b/core/src/mindustry/entities/units/AIController.java @@ -278,6 +278,10 @@ public class AIController implements UnitController{ } public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset){ + moveTo(target, circleLength, smooth, keepDistance, offset, false); + } + + public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset, boolean arrive){ if(target == null) return; vec.set(target).sub(unit); @@ -286,6 +290,11 @@ public class AIController implements UnitController{ vec.setLength(unit.speed() * length); + if(arrive){ + Tmp.v3.set(-unit.vel.x / unit.type.accel * 2f, -unit.vel.y / unit.type.accel * 2f).add((target.getX() - unit.x), (target.getY() - unit.y)); + vec.add(Tmp.v3).limit(unit.speed() * length); + } + if(length < -0.5f){ if(keepDistance){ vec.rotate(180f);