简化炮塔和武器站的自动瞄准

This commit is contained in:
Atsuishio 2025-06-24 01:17:35 +08:00 committed by Light_Quanta
parent 85b489e75c
commit 9ce6963408
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
2 changed files with 15 additions and 20 deletions

View file

@ -333,18 +333,6 @@ 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()) {
@ -827,8 +815,9 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
return new Vec3(rootPosition.x, rootPosition.y, rootPosition.z).vectorTo(new Vec3(targetPosition.x, targetPosition.y, targetPosition.z));
}
public Vec3 getGunnerVector(float pPartialTicks) {
Matrix4f transform = getGunnerBarrelTransform(pPartialTicks);
@Override
public Vec3 getBarrelVec(float ticks) {
Matrix4f transform = getGunnerBarrelTransform(ticks);
Vector4f rootPosition = transformPosition(transform, 0, 0, 0);
Vector4f targetPosition = transformPosition(transform, 0, 0, 1);
return new Vec3(rootPosition.x, rootPosition.y, rootPosition.z).vectorTo(new Vec3(targetPosition.x, targetPosition.y, targetPosition.z));

View file

@ -892,9 +892,10 @@ public abstract class VehicleEntity extends Entity {
}
}
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));
public void turretAutoAimFormVector(float ySpeed, float xSpeed, float minXAngle, float maxXAngle, Vec3 shootVec) {
//shootVec是需要让炮塔以这个角度发射的向量
float diffY = (float) Mth.wrapDegrees(-getYRotFromVector(shootVec) + getYRotFromVector(getBarrelVec(1)));
float diffX = (float) Mth.wrapDegrees(-getXRotFromVector(shootVec) + getXRotFromVector(getBarrelVec(1)));
this.turretTurnSound(diffX, diffY, 0.95f);
@ -911,9 +912,10 @@ 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));
public void passengerWeaponAutoAimFormVector(float ySpeed, float xSpeed, float minXAngle, float maxXAngle, Vec3 shootVec) {
//shootVec是需要让炮武器站以这个角度发射的向量
float diffY = (float) Mth.wrapDegrees(-getYRotFromVector(shootVec) + getYRotFromVector(getGunnerVector(1)));
float diffX = (float) Mth.wrapDegrees(-getXRotFromVector(shootVec) + getXRotFromVector(getGunnerVector(1)));
turretTurnSound(diffX, diffY, 0.95f);
@ -1134,6 +1136,10 @@ public abstract class VehicleEntity extends Entity {
return this.calculateViewVector(this.getBarrelXRot(pPartialTicks), this.getBarrelYRot(pPartialTicks));
}
public Vec3 getGunnerVector(float pPartialTicks) {
return this.getViewVector(pPartialTicks);
}
public float getBarrelXRot(float pPartialTicks) {
return Mth.lerp(pPartialTicks, turretXRotO - this.xRotO, getTurretXRot() - this.getXRot());
}