Minor command AI improvements

This commit is contained in:
Anuken
2022-02-18 16:35:29 -05:00
parent 9c1cb64c77
commit bc8842d0d7
3 changed files with 94 additions and 12 deletions

View File

@@ -256,10 +256,10 @@ public class AIController implements UnitController{
}
public void moveTo(Position target, float circleLength, float smooth){
moveTo(target, circleLength, smooth, unit.isFlying());
moveTo(target, circleLength, smooth, unit.isFlying(), null);
}
public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance){
public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset){
if(target == null) return;
vec.set(target).sub(unit);
@@ -267,6 +267,7 @@ public class AIController implements UnitController{
float length = circleLength <= 0.001f ? 1f : Mathf.clamp((unit.dst(target) - circleLength) / smooth, -1f, 1f);
vec.setLength(unit.speed() * length);
if(length < -0.5f){
if(keepDistance){
vec.rotate(180f);
@@ -277,6 +278,11 @@ public class AIController implements UnitController{
vec.setZero();
}
if(offset != null){
vec.add(offset);
vec.setLength(unit.speed() * length);
}
//do not move when infinite vectors are used.
if(vec.isNaN() || vec.isInfinite()) return;