Hello everyone.
I am trying to make player look at entity. Everything works fine, but I want to make camera move smoother. Now it just "stands" at one point and whenever I try to move camera, it's coming back to a point in very ugly way. Here's my code:
public static void lookAt(EntityPlayer player) {
EntityLiving ent = getFocusEntity();
double endX = ent.posX;
double endY = ent.posY - ent.getEyeHeight() + (ent.height - 1);
double endZ = ent.posZ;
double deltaX = endX - player.posX;
double deltaY = endY - player.posY;
double deltaZ = endZ - player.posZ;
double hypotenuse = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
float rotationYaw = (float) Math.toDegrees(Math.atan2(deltaX, deltaZ));
float rotationPitch = (float) Math.toDegrees(Math.atan2(deltaY, hypotenuse));
player.rotationYaw = -rotationYaw;
player.prevRotationYaw = -rotationYaw;
player.rotationPitch = -rotationPitch;
player.prevRotationPitch = -rotationPitch;
//player.capabilities.setPlayerWalkSpeed(0.05F);
}
I've found a smooth camera's code (one that turns on with F8), but don't know what to do with it.
if (this.mc.gameSettings.smoothCamera)
{
float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float f1 = f * f * f * 8.0F;
this.smoothCamFilterX = this.mouseFilterXAxis.smooth(this.smoothCamYaw, 0.05F * f1);
this.smoothCamFilterY = this.mouseFilterYAxis.smooth(this.smoothCamPitch, 0.05F * f1);
this.smoothCamPartialTicks = 0.0F;
this.smoothCamYaw = 0.0F;
this.smoothCamPitch = 0.0F;
}
else
{
this.smoothCamFilterX = 0.0F;
this.smoothCamFilterY = 0.0F;
this.mouseFilterXAxis.reset();
this.mouseFilterYAxis.reset();
}
if (this.mc.gameSettings.smoothCamera)
{
this.smoothCamYaw += f2;
this.smoothCamPitch += f3;
float f4 = partialTicks - this.smoothCamPartialTicks;
this.smoothCamPartialTicks = partialTicks;
f2 = this.smoothCamFilterX * f4;
f3 = this.smoothCamFilterY * f4;
this.mc.thePlayer.setAngles(f2, f3 * (float)i);
}
else
{
this.smoothCamYaw = 0.0F;
this.smoothCamPitch = 0.0F;
this.mc.thePlayer.setAngles(f2, f3 * (float)i);
}