mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-08-01 15:39:36 +07:00
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(){
|
||||
|
@ -83,4 +83,12 @@ abstract class MechComp implements Posc, Flyingc, Hitboxc, Unitc, Mechc, Elevati
|
||||
walked = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void approach(Vec2 vector){
|
||||
if(!vector.isZero(0.09f)){
|
||||
//mark walking state when moving in a controlled manner
|
||||
walked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
@Import Team team;
|
||||
@Import int id;
|
||||
@Import @Nullable Tile mineTile;
|
||||
@Import Vec2 vel;
|
||||
|
||||
private UnitController controller;
|
||||
UnitType type;
|
||||
@ -51,6 +52,10 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
moveAt(vector, type.accel);
|
||||
}
|
||||
|
||||
public void approach(Vec2 vector){
|
||||
vel.approachDelta(vector, type.accel * realSpeed() * floorSpeedMultiplier());
|
||||
}
|
||||
|
||||
public void aimLook(Position pos){
|
||||
aim(pos);
|
||||
lookAt(pos);
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=f0400adb14a72ca567ea3b48ea8c3a22c55e1b9e
|
||||
archash=9cb277618ace40f91c93987ad922c16922c1a8d6
|
||||
|
Reference in New Issue
Block a user