研究出通过向量解算武器站角度的方法

This commit is contained in:
Atsuishio 2025-06-23 10:15:33 +08:00 committed by Light_Quanta
parent 00fff469be
commit bfb9ca04cf
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 23 additions and 1 deletions

View file

@ -333,6 +333,18 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.refreshDimensions();
}
// public void autoAimTest() {
// Entity target = EntityFindUtil.findEntity(level(), entityData.get(LAST_ATTACKER_UUID));
// if (target != null) {
// Matrix4f transform = getGunTransform(1);
// Vector4f worldPosition = transformPosition(transform, 0, -0.25f, 0);
// Vec3 shootVec = new Vec3(getGunnerVector(1).x, getGunnerVector(1).y + 0.01f, getGunnerVector(1).z);
// Vec3 shootPos = new Vec3(worldPosition.x, worldPosition.y, worldPosition.z);
// Vec3 targetVec = shootPos.vectorTo(target.getBoundingBox().getCenter());
// passengerWeaponAutoAimFormVector(15, 15 , -10, 45, shootVec, targetVec);
// }
// }
@Override
public void terrainCompact(float w, float l) {
if (onGround()) {

View file

@ -889,7 +889,7 @@ public abstract class VehicleEntity extends Entity {
}
}
public void autoAimFormVector(float ySpeed, float xSpeed, float minXAngle, float maxXAngle, Vec3 shootVec, Vec3 targetVec) {
public void turretAutoAimFormVector(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));
@ -908,6 +908,16 @@ public abstract class VehicleEntity extends Entity {
turretYRotLock = Mth.clamp(0.9f * diffY, min, max);
}
public void passengerWeaponAutoAimFormVector(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));
turretTurnSound(diffX, diffY, 0.95f);
this.setGunXRot(Mth.clamp(this.getGunXRot() + Mth.clamp(0.5f * diffX, -xSpeed, xSpeed), -maxXAngle, -minXAngle));
this.setGunYRot(this.getGunYRot() - Mth.clamp(0.5f * diffY, -ySpeed, ySpeed));
}
public void gunnerAngle(float ySpeed, float xSpeed) {
Entity gunner = this.getNthEntity(1);