研究出通过向量解算炮塔角度的方法

This commit is contained in:
Atsuishio 2025-06-23 01:52:43 +08:00 committed by Light_Quanta
parent 16807dda03
commit 0aee8d49cd
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -889,6 +889,25 @@ public abstract class VehicleEntity extends Entity {
} }
} }
public void autoAimFormVector(float ySpeed, float xSpeed, float minXAngle, float maxXAngle, Vec3 shootVec, Vec3 targetVec) {
float diffY = (float) Mth.wrapDegrees(-getYRotFromVector(targetVec) + getYRotFromVector(shootVec));
float diffX = (float) Mth.wrapDegrees(-getXRotFromVector(targetVec) + getXRotFromVector(shootVec));
this.turretTurnSound(diffX, diffY, 0.95f);
if (entityData.get(TURRET_DAMAGED)) {
ySpeed *= 0.2f;
xSpeed *= 0.2f;
}
float min = -ySpeed + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
float max = ySpeed + (float) (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT);
this.setTurretXRot(Mth.clamp(this.getTurretXRot() + Mth.clamp(0.5f * diffX, -xSpeed, xSpeed), -maxXAngle, -minXAngle));
this.setTurretYRot(this.getTurretYRot() - Mth.clamp(0.5f * diffY, min, max));
turretYRotLock = Mth.clamp(0.9f * diffY, min, max);
}
public void gunnerAngle(float ySpeed, float xSpeed) { public void gunnerAngle(float ySpeed, float xSpeed) {
Entity gunner = this.getNthEntity(1); Entity gunner = this.getNthEntity(1);