diff --git a/core/src/io/anuke/mindustry/ai/Pathfind.java b/core/src/io/anuke/mindustry/ai/Pathfind.java index 9ce31fe13f..564d9c53fe 100644 --- a/core/src/io/anuke/mindustry/ai/Pathfind.java +++ b/core/src/io/anuke/mindustry/ai/Pathfind.java @@ -40,7 +40,11 @@ public class Pathfind{ target = path[enemy.node]; } - + + //near the core, stop + if(enemy.node == path.length - 1){ + vector.set(target.worldx(), target.worldy()); + } return vector.set(target.worldx(), target.worldy()); diff --git a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java index 0f6533049e..4ba759688c 100644 --- a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java +++ b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java @@ -58,8 +58,17 @@ public class Enemy extends DestructibleEntity{ } void move(){ - Vector2 vec = Pathfind.find(this); - vec.sub(x, y).setLength(speed); + boolean nearCore = distanceTo(World.core.worldx(), World.core.worldy()) <= range - 14f; + + Vector2 vec; + + if(nearCore){ + vec = Tmp.v2.setZero(); + target = World.core.entity; + }else{ + vec = Pathfind.find(this); + vec.sub(x, y).setLength(speed); + } Array entities = Entities.getNearby(x, y, range); @@ -79,7 +88,7 @@ public class Enemy extends DestructibleEntity{ move(vec.x*Timers.delta(), vec.y*Timers.delta()); - if(Timers.get(this, "target", 15)){ + if(Timers.get(this, "target", 15) && !nearCore){ target = World.findTileTarget(x, y, null, range, false); //no tile found