From d7cd9ab74409d3d4980943ca92ccab577243bad8 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 8 Feb 2022 21:00:21 -0500 Subject: [PATCH] Stop moving when near destination --- core/src/mindustry/ai/types/CommandAI.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/mindustry/ai/types/CommandAI.java b/core/src/mindustry/ai/types/CommandAI.java index e56afe5181..39953aa7f3 100644 --- a/core/src/mindustry/ai/types/CommandAI.java +++ b/core/src/mindustry/ai/types/CommandAI.java @@ -21,14 +21,20 @@ public class CommandAI extends AIController{ targetPos.set(attackTarget); } + + if(targetPos != null){ - moveTo(targetPos, attackTarget != null ? unit.type.range - 10f : 5f); + moveTo(targetPos, attackTarget != null ? unit.type.range - 10f : 0f); if(unit.isFlying()){ unit.lookAt(targetPos); }else{ faceTarget(); } + + if(attackTarget == null && unit.within(targetPos, Math.max(5f, unit.hitSize) / 2.9f)){ + targetPos = null; + } }else if(target != null){ faceTarget(); }