Fixed omnidirectional shooting with ignored rotation

This commit is contained in:
Anuken
2020-02-16 13:49:29 -05:00
parent 7a8bd82f8e
commit e71230755d
4 changed files with 13 additions and 6 deletions

View File

@@ -520,6 +520,7 @@ public class EntityProcess extends BaseProcessor{
.returns(int.class).addModifiers(Modifier.PUBLIC).addStatement("return " + def.classID).build()); .returns(int.class).addModifiers(Modifier.PUBLIC).addStatement("return " + def.classID).build());
} }
idBuilder.addStaticBlock(idStore.build()); idBuilder.addStaticBlock(idStore.build());
write(idBuilder); write(idBuilder);

View File

@@ -31,7 +31,7 @@ public class UnitTypes implements ContentList{
mass = 1.75f; mass = 1.75f;
health = 130; health = 130;
weapons.add(new Weapon("chain-blaster"){{ weapons.add(new Weapon("chain-blaster"){{
reload = 28f; reload = 14f;
x = 4f; x = 4f;
alternate = true; alternate = true;
ejectEffect = Fx.shellEjectSmall; ejectEffect = Fx.shellEjectSmall;

View File

@@ -67,7 +67,11 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
float axisX = this.x + Angles.trnsx(rotation, axisXOffset, weapon.y), float axisX = this.x + Angles.trnsx(rotation, axisXOffset, weapon.y),
axisY = this.y + Angles.trnsy(rotation, axisXOffset, weapon.y); axisY = this.y + Angles.trnsy(rotation, axisXOffset, weapon.y);
mount.rotation = Angles.moveToward(mount.rotation, Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - rotation(), weapon.rotateSpeed); mount.targetRotation = Angles.angle(axisX, axisY, mount.aimX, mount.aimY) - rotation();
mount.rotation = Angles.moveToward(mount.rotation, mount.targetRotation, weapon.rotateSpeed);
}else{
mount.rotation = this.rotation;
mount.targetRotation = angleTo(mount.aimX, mount.aimY);
} }
if(mount.shoot){ if(mount.shoot){
@@ -75,17 +79,17 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
//shoot if applicable //shoot if applicable
//TODO only shoot if angle is reached, don't shoot inaccurately //TODO only shoot if angle is reached, don't shoot inaccurately
if(mount.reload <= 0.0001f){ if(mount.reload <= 0.0001f && Angles.within(mount.rotation, mount.targetRotation, 1.5f)){
for(int i : (weapon.mirror && !weapon.alternate ? Mathf.signs : Mathf.one)){ for(int i : (weapon.mirror && !weapon.alternate ? Mathf.signs : Mathf.one)){
i *= Mathf.sign(weapon.flipped) * Mathf.sign(mount.side); i *= Mathf.sign(weapon.flipped) * Mathf.sign(mount.side);
//m a t h //m a t h
float weaponRotation = rotation + (weapon.rotate ? mount.rotation : 0); float weaponRotation = rotation + (weapon.rotate ? mount.rotation : 0);
float mountX = this.x + Angles.trnsx(rotation, weapon.x * i, weapon.y), float mountX = this.x + Angles.trnsx(rotation, weapon.x * i, weapon.y),
mountY = this.y + Angles.trnsy(rotation, weapon.x * i, weapon.y); mountY = this.y + Angles.trnsy(rotation, weapon.x * i, weapon.y);
float shootX = mountX + Angles.trnsx(weaponRotation, weapon.shootX * i, weapon.shootY), float shootX = mountX + Angles.trnsx(weaponRotation, weapon.shootX * i, weapon.shootY),
shootY = mountY + Angles.trnsy(weaponRotation, weapon.shootX * i, weapon.shootY); shootY = mountY + Angles.trnsy(weaponRotation, weapon.shootX * i, weapon.shootY);
float shootAngle = weapon.rotate ? weaponRotation + 90 : Angles.angle(shootX, shootY, mount.aimX, mount.aimY); float shootAngle = weapon.rotate ? weaponRotation + 90 : Angles.angle(shootX, shootY, mount.aimX, mount.aimY) + (this.rotation - angleTo(mount.aimX, mount.aimY));
shoot(weapon, shootX, shootY, shootAngle); shoot(weapon, shootX, shootY, shootAngle);
} }

View File

@@ -9,6 +9,8 @@ public class WeaponMount{
public float reload; public float reload;
/** rotation relative to the unit this mount is on */ /** rotation relative to the unit this mount is on */
public float rotation; public float rotation;
/** destination rotation; do not modify! */
public float targetRotation;
/** aiming position in world coordinates */ /** aiming position in world coordinates */
public float aimX, aimY; public float aimX, aimY;
/** side that's being shot - only valid for mirrors */ /** side that's being shot - only valid for mirrors */