From 3be5296572a27b2ece18c59b64fc7b10c9ea79e2 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 4 Aug 2021 13:52:17 -0400 Subject: [PATCH] Fixed #5699 --- core/src/mindustry/ai/types/LogicAI.java | 10 ++++++++-- core/src/mindustry/entities/comp/UnitComp.java | 8 ++++++++ core/src/mindustry/input/DesktopInput.java | 2 ++ core/src/mindustry/input/MobileInput.java | 5 +---- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/core/src/mindustry/ai/types/LogicAI.java b/core/src/mindustry/ai/types/LogicAI.java index 193e5aaf48..d33d5ad372 100644 --- a/core/src/mindustry/ai/types/LogicAI.java +++ b/core/src/mindustry/ai/types/LogicAI.java @@ -102,7 +102,7 @@ public class LogicAI extends AIController{ } //look where moving if there's nothing to aim at - if(!shoot){ + if(!shoot || !unit.type.omniMovement){ unit.lookAt(unit.prefRotation()); }else if(unit.hasWeapons() && unit.mounts.length > 0 && !unit.mounts[0].weapon.ignoreRotation){ //if there is, look at the object unit.lookAt(unit.mounts[0].aimX, unit.mounts[0].aimY); @@ -131,7 +131,13 @@ public class LogicAI extends AIController{ //do not move when infinite vectors are used. if(vec.isNaN() || vec.isInfinite()) return; - unit.approach(vec); + if(unit.type.omniMovement){ + unit.approach(vec); + }else{ + unit.rotateMove(vec); + } + + } @Override diff --git a/core/src/mindustry/entities/comp/UnitComp.java b/core/src/mindustry/entities/comp/UnitComp.java index 8da31fb2e1..ae4001d25f 100644 --- a/core/src/mindustry/entities/comp/UnitComp.java +++ b/core/src/mindustry/entities/comp/UnitComp.java @@ -59,6 +59,14 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I vel.approachDelta(vector, type.accel * realSpeed()); } + public void rotateMove(Vec2 vec){ + moveAt(Tmp.v2.trns(rotation, vec.len())); + + if(!vec.isZero()){ + rotation = Angles.moveToward(rotation, vec.angle(), type.rotateSpeed * Math.max(Time.delta, 1)); + } + } + public void aimLook(Position pos){ aim(pos); lookAt(pos); diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 11f37f34dc..c2d61af046 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -645,6 +645,8 @@ public class DesktopInput extends InputHandler{ if(omni){ unit.moveAt(movement); }else{ + unit.rotateMove(movement); + unit.moveAt(Tmp.v2.trns(unit.rotation, movement.len())); //problem: actual unit rotation is controlled by velocity, but velocity is 1) unpredictable and 2) can be set to 0 diff --git a/core/src/mindustry/input/MobileInput.java b/core/src/mindustry/input/MobileInput.java index 7429eddaaa..2480cad5ab 100644 --- a/core/src/mindustry/input/MobileInput.java +++ b/core/src/mindustry/input/MobileInput.java @@ -922,10 +922,7 @@ public class MobileInput extends InputHandler implements GestureListener{ if(omni){ unit.moveAt(movement); }else{ - unit.moveAt(Tmp.v2.trns(unit.rotation, movement.len())); - if(!movement.isZero()){ - unit.rotation = Angles.moveToward(unit.rotation, movement.angle(), unit.type.rotateSpeed * Math.max(Time.delta, 1)); - } + unit.rotateMove(movement); } //update shooting if not building + not mining