Improved approach behavior in formations/logic
This commit is contained in:
@@ -37,7 +37,6 @@ public class FormationAI extends AIController implements FormationMember{
|
||||
}
|
||||
|
||||
unit.controlWeapons(true, leader.isShooting);
|
||||
// unit.moveAt(Tmp.v1.set(deltaX, deltaY).limit(unit.type().speed));
|
||||
|
||||
unit.aim(leader.aimX(), leader.aimY());
|
||||
|
||||
@@ -47,17 +46,10 @@ public class FormationAI extends AIController implements FormationMember{
|
||||
unit.lookAt(unit.vel.angle());
|
||||
}
|
||||
|
||||
Vec2 realtarget = vec.set(target);
|
||||
Vec2 realtarget = vec.set(target).add(leader.vel.x, leader.vel.y);
|
||||
|
||||
float margin = 4f;
|
||||
|
||||
float speed = unit.realSpeed();
|
||||
|
||||
if(unit.dst(realtarget) <= margin){
|
||||
//unit.vel.approachDelta(Vec2.ZERO, speed * type.accel / 2f);
|
||||
}else{
|
||||
unit.moveAt(realtarget.sub(unit).limit(speed));
|
||||
}
|
||||
float speed = unit.realSpeed() * unit.floorSpeedMultiplier();
|
||||
unit.approach(Mathf.arrive(unit.x, unit.y, realtarget.x, realtarget.y, unit.vel, 0f, 0.01f, speed, 1f));
|
||||
|
||||
if(unit.canMine() && leader.canMine()){
|
||||
if(leader.mineTile != null && unit.validMine(leader.mineTile)){
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mindustry.ai.types;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.ai.*;
|
||||
@@ -67,7 +68,7 @@ public class LogicAI extends AIController{
|
||||
moveTo(Tmp.v1.set(moveX, moveY), 1f, 30f);
|
||||
}
|
||||
case approach -> {
|
||||
moveTo(Tmp.v1.set(moveX, moveY), moveRad - 8f, 8f);
|
||||
moveTo(Tmp.v1.set(moveX, moveY), moveRad - 7f, 7);
|
||||
}
|
||||
case pathfind -> {
|
||||
Building core = unit.closestEnemyCore();
|
||||
@@ -112,6 +113,24 @@ public class LogicAI extends AIController{
|
||||
return radars.add(radar);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveTo(Position target, float circleLength, float smooth){
|
||||
if(target == null) return;
|
||||
|
||||
vec.set(target).sub(unit);
|
||||
|
||||
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / smooth, -1f, 1f);
|
||||
|
||||
vec.setLength(unit.realSpeed() * length);
|
||||
if(length < -0.5f){
|
||||
vec.rotate(180f);
|
||||
}else if(length < 0){
|
||||
vec.setZero();
|
||||
}
|
||||
|
||||
unit.approach(vec);
|
||||
}
|
||||
|
||||
//always retarget
|
||||
@Override
|
||||
protected boolean retarget(){
|
||||
|
||||
Reference in New Issue
Block a user