继续优化无人机的飞控

This commit is contained in:
Atsuihsio 2024-07-28 20:34:38 +08:00
parent ec88c89e92
commit 1ad4ea56a9
2 changed files with 11 additions and 11 deletions

View file

@ -190,17 +190,17 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
if (this.getPersistentData().getBoolean("left")) { if (this.getPersistentData().getBoolean("left")) {
this.entityData.set(MOVEX,-1.5f); this.entityData.set(MOVEX,-1.5f);
this.entityData.set(ROTX,this.entityData.get(ROTX) + 0.13f); this.entityData.set(ROTX,Mth.clamp(this.entityData.get(ROTX) + 0.05f, -0.5f, 0.5f));
} }
if (this.getPersistentData().getBoolean("right")) { if (this.getPersistentData().getBoolean("right")) {
this.entityData.set(MOVEX,1.5f); this.entityData.set(MOVEX,1.5f);
this.entityData.set(ROTX,this.entityData.get(ROTX) - 0.13f); this.entityData.set(ROTX,Mth.clamp(this.entityData.get(ROTX) - 0.05f, -0.5f, 0.5f));
} }
if (this.entityData.get(ROTX) > 0) { if (this.entityData.get(ROTX) > 0) {
this.entityData.set(ROTX, Mth.clamp(this.entityData.get(ROTX) - 0.55f * (float) Math.pow(this.entityData.get(ROTX),2), 0, 1f)); this.entityData.set(ROTX, Mth.clamp(this.entityData.get(ROTX) - 0.025f, 0, 0.5f));
} else { } else {
this.entityData.set(ROTX, Mth.clamp(this.entityData.get(ROTX) + 0.55f * (float) Math.pow(this.entityData.get(ROTX),2), -1f, 0)); this.entityData.set(ROTX, Mth.clamp(this.entityData.get(ROTX) + 0.025f, -0.5f, 0));
} }
if (!this.getPersistentData().getBoolean("left") && !this.getPersistentData().getBoolean("right")) { if (!this.getPersistentData().getBoolean("left") && !this.getPersistentData().getBoolean("right")) {
@ -214,17 +214,17 @@ public class DroneEntity extends PathfinderMob implements GeoEntity {
if (this.getPersistentData().getBoolean("forward")) { if (this.getPersistentData().getBoolean("forward")) {
this.entityData.set(MOVEZ,this.entityData.get(MOVEZ) - 0.15f); this.entityData.set(MOVEZ,this.entityData.get(MOVEZ) - 0.15f);
this.entityData.set(ROTZ,this.entityData.get(ROTZ) - 0.13f); this.entityData.set(ROTZ,Mth.clamp(this.entityData.get(ROTZ) - 0.05f, -0.5f, 0.5f));
} }
if (this.getPersistentData().getBoolean("backward")) { if (this.getPersistentData().getBoolean("backward")) {
this.entityData.set(MOVEZ,this.entityData.get(MOVEZ) + 0.15f); this.entityData.set(MOVEZ,this.entityData.get(MOVEZ) + 0.15f);
this.entityData.set(ROTZ,this.entityData.get(ROTZ) + 0.13f); this.entityData.set(ROTZ,Mth.clamp(this.entityData.get(ROTZ) + 0.05f, -0.5f, 0.5f));
} }
if (this.entityData.get(ROTZ) > 0) { if (this.entityData.get(ROTZ) > 0) {
this.entityData.set(ROTZ, Mth.clamp(this.entityData.get(ROTZ) - 0.55f * (float) Math.pow(this.entityData.get(ROTZ),2), 0, 1f)); this.entityData.set(ROTZ, Mth.clamp(this.entityData.get(ROTZ) - 0.025f, 0, 0.5f));
} else { } else {
this.entityData.set(ROTZ, Mth.clamp(this.entityData.get(ROTZ) + 0.55f * (float) Math.pow(this.entityData.get(ROTZ),2), -1f, 0)); this.entityData.set(ROTZ, Mth.clamp(this.entityData.get(ROTZ) + 0.025f, -0.5f, 0));
} }
if (this.entityData.get(MOVEZ) >= 0) { if (this.entityData.get(MOVEZ) >= 0) {

View file

@ -52,7 +52,7 @@ public class ClientEventHandler {
data.putDouble("Cannon_xRot", Mth.clamp(0.2 * xRot, -3, 3)); data.putDouble("Cannon_xRot", Mth.clamp(0.2 * xRot, -3, 3));
data.putDouble("Cannon_yRot", Mth.clamp(1 * yRot, -15, 15)); data.putDouble("Cannon_yRot", Mth.clamp(1 * yRot, -15, 15));
data.putDouble("droneCameraRotX", Mth.clamp(0.5f * xRot, -10, 10)); data.putDouble("droneCameraRotX", Mth.clamp(0.25f * xRot, -10, 10));
data.putDouble("droneCameraRotY", Mth.clamp(0.25f * yRot, -20, 10)); data.putDouble("droneCameraRotY", Mth.clamp(0.25f * yRot, -20, 10));
} }
@ -104,8 +104,8 @@ public class ClientEventHandler {
data.putDouble("droneRotX", Mth.clamp(data.getDouble("droneRotX") + 0.2 * Math.pow(drone.getEntityData().get(ROTX) - data.getDouble("droneRotX"), 2),Double.NEGATIVE_INFINITY,drone.getEntityData().get(ROTX))); data.putDouble("droneRotX", Mth.clamp(data.getDouble("droneRotX") + 0.2 * Math.pow(drone.getEntityData().get(ROTX) - data.getDouble("droneRotX"), 2),Double.NEGATIVE_INFINITY,drone.getEntityData().get(ROTX)));
} }
event.setPitch((float) (pitch + data.getDouble("droneCameraRotX") - 0.45f * Mth.RAD_TO_DEG * data.getDouble("droneRotZ"))); event.setPitch((float) (pitch + data.getDouble("droneCameraRotX") - 0.15f * Mth.RAD_TO_DEG * data.getDouble("droneRotZ")));
event.setRoll((float) (roll + data.getDouble("droneCameraRotY") - 0.8f * Mth.RAD_TO_DEG * data.getDouble("droneRotX"))); event.setRoll((float) (roll + data.getDouble("droneCameraRotY") - 0.5f * Mth.RAD_TO_DEG * data.getDouble("droneRotX")));
} }