Fixed unit movement overshoot

This commit is contained in:
Anuken
2022-07-31 10:37:55 -04:00
parent 3d64047a91
commit 1fe988adc2
2 changed files with 10 additions and 1 deletions

View File

@@ -127,7 +127,7 @@ public class CommandAI extends AIController{
attackTarget != null && unit.within(attackTarget, engageRange) ? engageRange :
unit.isGrounded() ? 0f :
attackTarget != null ? engageRange :
0f, unit.isFlying() ? 40f : 100f, false, null);
0f, unit.isFlying() ? 40f : 100f, false, null, true);
}
//calculateFlock().limit(unit.speed() * flockMult)

View File

@@ -278,6 +278,10 @@ public class AIController implements UnitController{
}
public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset){
moveTo(target, circleLength, smooth, keepDistance, offset, false);
}
public void moveTo(Position target, float circleLength, float smooth, boolean keepDistance, @Nullable Vec2 offset, boolean arrive){
if(target == null) return;
vec.set(target).sub(unit);
@@ -286,6 +290,11 @@ public class AIController implements UnitController{
vec.setLength(unit.speed() * length);
if(arrive){
Tmp.v3.set(-unit.vel.x / unit.type.accel * 2f, -unit.vel.y / unit.type.accel * 2f).add((target.getX() - unit.x), (target.getY() - unit.y));
vec.add(Tmp.v3).limit(unit.speed() * length);
}
if(length < -0.5f){
if(keepDistance){
vec.rotate(180f);