优化坦克武器站旋转逻辑

This commit is contained in:
Atsuihsio 2025-03-09 21:18:03 +08:00
parent 7e4f5eaf9c
commit 0562fcd527
2 changed files with 14 additions and 12 deletions

View file

@ -66,7 +66,7 @@ public class Yx100Renderer extends GeoEntityRenderer<Yx100Entity> {
}
if (name.equals("jiqiang")) {
bone.setRotY(Mth.lerp(partialTick, animatable.gunYRotO, animatable.getGunYRot()) * Mth.DEG_TO_RAD - (animatable.getNthEntity(1) == null ? 0 : Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD));
bone.setRotY(Mth.lerp(partialTick, animatable.gunYRotO, animatable.getGunYRot()) * Mth.DEG_TO_RAD - Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD);
}
if (name.equals("qiangguan")) {
bone.setRotX(-Mth.lerp(partialTick, animatable.gunXRotO, animatable.getGunXRot()) * Mth.DEG_TO_RAD);

View file

@ -88,7 +88,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public float turretXRot;
public float turretYRotO;
public float turretXRotO;
public float turretRot;
public float gunYRot;
public float gunXRot;
public float gunYRotO;
@ -596,24 +596,26 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.95f * diffX, -5, 5), -30f, 4f));
this.setTurretYRot(this.getTurretYRot() + Mth.clamp(0.9f * diffY, min, max));
turretRot = Mth.clamp(0.9f * diffY, min, max);
}
private void gunnerAngle() {
Entity gunner = this.getNthEntity(1);
if (!(gunner instanceof Player)) return;
float diffY = 0;
float diffX = 0;
float speed = 1;
if (gunner instanceof Player) {
float gunAngle = -Mth.wrapDegrees(gunner.getYHeadRot() - this.getYRot());
float diffY;
float diffX;
diffY = Mth.wrapDegrees(gunAngle - getGunYRot());
diffX = Mth.wrapDegrees(gunner.getXRot() - this.getGunXRot());
turretTurnSound(diffX, diffY, 0.95f);
speed = 0;
}
this.setGunXRot(Mth.clamp(this.getGunXRot() + Mth.clamp(0.95f * diffX, -10, 10), -60f, 12.5f));
this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -15, 15));
this.setGunYRot(this.getGunYRot() + Mth.clamp(0.9f * diffY, -15, 15) + speed * turretRot);
}
@Override