mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-03 13:30:25 +07:00
Enemy AI now stops near core when in range; collision avoidance
This commit is contained in:
parent
12aa8c406b
commit
60a5782a24
@ -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());
|
||||
|
||||
|
@ -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<SolidEntity> 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
|
||||
|
Loading…
Reference in New Issue
Block a user