Skip to content
Permalink
Browse files

Smoother turret movement.

  • Loading branch information...
Ri5ux Ri5ux
Ri5ux authored and Ri5ux committed Jul 11, 2019
1 parent 1bcae9b commit c604a5adb6aef5e0c5b229b614de644513b2c533
@@ -3,6 +3,7 @@
import org.avp.tile.TileEntityTurret;

import com.asx.mdx.lib.client.util.models.Model;
import com.asx.mdx.lib.util.Game;

import net.minecraft.client.model.ModelRenderer;

@@ -150,7 +151,12 @@ public void render(Object obj)
if (tile != null)
{
float rotationYaw = (-tile.getRotationYaw()) / (180F / (float) Math.PI);
float rotationYawPrev = (-tile.getRotationPrev().yaw) / (180F / (float) Math.PI);
float rotationPitch = -tile.getRotationPitch() / (180F / (float) Math.PI);
float rotationPitchPrev = -tile.getRotationPrev().pitch / (180F / (float) Math.PI);

rotationYaw = rotationYawPrev + (rotationYaw - rotationYawPrev) * Game.partialTicks();
rotationPitch = rotationPitchPrev + (rotationPitch - rotationPitchPrev) * Game.partialTicks();

barrel.rotateAngleY = rotationYaw;
barrel.rotateAngleX = rotationPitch;
@@ -94,6 +94,7 @@
private ContainerTurret container;
private Pos pos;
private Rotation rot;
private Rotation rotPrev;
private Pos foc;
private Rotation focrot;
private Item itemAmmo;
@@ -111,6 +112,7 @@ public TileEntityTurret()
this.cycleCount = getBaseCycleCount();
this.curAmmo = 0;
this.rot = new Rotation(0F, 0F);
this.rotPrev = new Rotation(0F, 0F);
this.focrot = new Rotation(0F, 0F);
this.ammoDisplayEnabled = false;
this.timeoutMax = 60;
@@ -347,26 +349,32 @@ public void lookAtFocusPoint()
{
if (Math.ceil(this.getRotationYaw()) < Math.ceil(this.focrot.yaw))
{
this.rotPrev.yaw = this.rot.yaw;
this.rot.yaw += 1;
}
else if (Math.ceil(this.getRotationYaw()) > Math.ceil(this.focrot.yaw))
{
this.rotPrev.yaw = this.rot.yaw;
this.rot.yaw -= 1;
}

if (Math.ceil(this.getRotationPitch()) < Math.ceil(this.focrot.pitch))
{
this.rotPrev.pitch = this.rot.pitch;
this.rot.pitch += 1;
}
else if (Math.ceil(this.getRotationPitch()) > Math.ceil(this.focrot.pitch))
{
this.rotPrev.pitch = this.rot.pitch;
this.rot.pitch -= 1;
}

double focus = 1;

if (Math.ceil(this.getRotationPitch()) >= Math.ceil(this.focrot.pitch - focus) && Math.ceil(this.getRotationPitch()) <= Math.ceil(this.focrot.pitch + focus) && Math.ceil(this.getRotationYaw()) >= Math.ceil(this.focrot.yaw - focus) && Math.ceil(this.getRotationYaw()) <= Math.ceil(this.focrot.yaw + focus))
{
this.rotPrev.pitch = this.rot.pitch;
this.rotPrev.yaw = this.rot.yaw;
this.rot.pitch = this.focrot.pitch;
this.rot.yaw = this.focrot.yaw;
}
@@ -479,7 +487,7 @@ public Rotation turnTurretToPoint(Pos pos, Rotation rotation, float deltaYaw, fl

float newYaw = (float) (Math.atan2(z, x) * 180.0D / Math.PI) - 90.0F;
float f1 = (float) (-(Math.atan2(y, sq) * 180.0D / Math.PI));

return rotation.setYaw(MDXMath.wrapAngle(this.rot.yaw, newYaw, deltaYaw)).setPitch(MDXMath.wrapAngle(this.rot.pitch, f1, deltaPitch));
}

@@ -778,6 +786,11 @@ public float getRotationPitch()
{
return this.rot.pitch;
}

public Rotation getRotationPrev()
{
return rotPrev;
}

public boolean isFiring()
{

0 comments on commit c604a5a

Please sign in to comment.
You can’t perform that action at this time.