From 3162f043d2b4a74d832fbe3e0b60a49cfae3398d Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 17 Mar 2024 12:24:11 -0400 Subject: [PATCH] Possible weapon autotarget fire fix --- core/src/mindustry/type/Weapon.java | 48 +++++++++++++++-------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index 1e4378ebe5..151a0f69ee 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -297,31 +297,9 @@ public class Weapon implements Cloneable{ mount.warmup = Mathf.lerpDelta(mount.warmup, warmupTarget, shootWarmupSpeed); } - //rotate if applicable - if(rotate && (mount.rotate || mount.shoot) && can){ - float axisX = unit.x + Angles.trnsx(unit.rotation - 90, x, y), - axisY = unit.y + Angles.trnsy(unit.rotation - 90, x, y); - - mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - unit.rotation; - mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, rotateSpeed * Time.delta); - if(rotationLimit < 360){ - float dst = Angles.angleDist(mount.rotation, baseRotation); - if(dst > rotationLimit/2f){ - mount.rotation = Angles.moveToward(mount.rotation, baseRotation, dst - rotationLimit/2f); - } - } - }else if(!rotate){ - mount.rotation = baseRotation; - mount.targetRotation = unit.angleTo(mount.aimX, mount.aimY); - } - float - weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation), mountX = unit.x + Angles.trnsx(unit.rotation - 90, x, y), - mountY = unit.y + Angles.trnsy(unit.rotation - 90, x, y), - bulletX = mountX + Angles.trnsx(weaponRotation, this.shootX, this.shootY), - bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX, this.shootY), - shootAngle = bulletRotation(unit, mount, bulletX, bulletY); + mountY = unit.y + Angles.trnsy(unit.rotation - 90, x, y); //find a new target if(!controllable && autoTarget){ @@ -355,6 +333,30 @@ public class Weapon implements Cloneable{ //logic will return shooting as false even if these return true, which is fine } + //rotate if applicable + if(rotate && (mount.rotate || mount.shoot) && can){ + float axisX = unit.x + Angles.trnsx(unit.rotation - 90, x, y), + axisY = unit.y + Angles.trnsy(unit.rotation - 90, x, y); + + mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - unit.rotation; + mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, rotateSpeed * Time.delta); + if(rotationLimit < 360){ + float dst = Angles.angleDist(mount.rotation, baseRotation); + if(dst > rotationLimit/2f){ + mount.rotation = Angles.moveToward(mount.rotation, baseRotation, dst - rotationLimit/2f); + } + } + }else if(!rotate){ + mount.rotation = baseRotation; + mount.targetRotation = unit.angleTo(mount.aimX, mount.aimY); + } + + float + weaponRotation = unit.rotation - 90 + (rotate ? mount.rotation : baseRotation), + bulletX = mountX + Angles.trnsx(weaponRotation, this.shootX, this.shootY), + bulletY = mountY + Angles.trnsy(weaponRotation, this.shootX, this.shootY), + shootAngle = bulletRotation(unit, mount, bulletX, bulletY); + if(alwaysShooting) mount.shoot = true; //update continuous state