Skip to main content
Added more information about my question
Source Link
Day Trip
  • 75
  • 1
  • 9

I am coding a custom client for Minecraft using MCP. (Please no hate, I'm not making a hacked client!) I have two variables currentYaw which is the current yaw rotation of the player, and targetYaw which is the yaw rotation that I want the player to be looking at. I have a function called lerpAngle and here is the code for it:

public static float lerpAngle(float fromRadians, float toRadians, float progress) {
    float delta = ((toRadians - fromRadians + PI2 + PI) % PI2) - PI;
    return (fromRadians + delta * progress + PI2) % PI2;
}

There is a float in minecraft.timer called elapsedPartialTicks. This variable is always between 0 and 1. Now I want to interpolate between currentYaw and targetYaw so that the transition is smooth. I passed in elapsedPartialTicks as progress but the screen moves way too fast. I am running all this code from the tick method.

What can I do to interpolate smoothly between currentYaw and targetYaw, but without the screen moving so fast.

Thank you for all the help!

Please note that I don't need any code, so it doesn't matter if you're answer is based on Forge or MCP. I just need a logic; I can write the code myself.

Again, thank you so much!

EDIT: In my current implementation, I have the following code:

float progress = (cameraInterpolationTimer.getCurrentTicks() + minecraft.timer.elapsedPartialTicks) / cameraInterpolationTimer.getTargetTicks();
minecraft.thePlayer.rotationYaw = (float) Math.toDegrees(InterpolationMath.angleLinearInterpolate((float) Math.toRadians(minecraft.thePlayer.rotationYaw), (float) Math.toRadians(yaw), progress));
minecraft.thePlayer.rotationPitch = (float) Math.toDegrees(InterpolationMath.angleLinearInterpolate((float) Math.toRadians(minecraft.thePlayer.rotationPitch), (float) Math.toRadians(pitch), progress));

The variables pitch and yaw are the rotations that I intend on facing. I also have variables prevPitch and prevYaw, which are set to pitch and yaw at the end of the function. cameraInterpolationTimer is a repeating timer (which is currently at a fixed interval) which gets reset when the difference between yaw and prevYaw is too large (because the target is moving; thus the pitch and yaw variables change each time the function is called). The function getCurrentTicks in the timer returns the amount of time that is passed since the timer was either created or reset. getTargetTicks is just another way of returning the fixed interval that the timer has been set for.

This should be interpolating smoothly to face the target yaw and pitch. It is working, but there is a mild stutter. It is pretty mild, but it is very annoying to look at and can be easily seen. How can I solve this?

I am coding a custom client for Minecraft using MCP. (Please no hate, I'm not making a hacked client!) I have two variables currentYaw which is the current yaw rotation of the player, and targetYaw which is the yaw rotation that I want the player to be looking at. I have a function called lerpAngle and here is the code for it:

public static float lerpAngle(float fromRadians, float toRadians, float progress) {
    float delta = ((toRadians - fromRadians + PI2 + PI) % PI2) - PI;
    return (fromRadians + delta * progress + PI2) % PI2;
}

There is a float in minecraft.timer called elapsedPartialTicks. This variable is always between 0 and 1. Now I want to interpolate between currentYaw and targetYaw so that the transition is smooth. I passed in elapsedPartialTicks as progress but the screen moves way too fast. I am running all this code from the tick method.

What can I do to interpolate smoothly between currentYaw and targetYaw, but without the screen moving so fast.

Thank you for all the help!

Please note that I don't need any code, so it doesn't matter if you're answer is based on Forge or MCP. I just need a logic; I can write the code myself.

Again, thank you so much!

I am coding a custom client for Minecraft using MCP. (Please no hate, I'm not making a hacked client!) I have two variables currentYaw which is the current yaw rotation of the player, and targetYaw which is the yaw rotation that I want the player to be looking at. I have a function called lerpAngle and here is the code for it:

public static float lerpAngle(float fromRadians, float toRadians, float progress) {
    float delta = ((toRadians - fromRadians + PI2 + PI) % PI2) - PI;
    return (fromRadians + delta * progress + PI2) % PI2;
}

There is a float in minecraft.timer called elapsedPartialTicks. This variable is always between 0 and 1. Now I want to interpolate between currentYaw and targetYaw so that the transition is smooth. I passed in elapsedPartialTicks as progress but the screen moves way too fast. I am running all this code from the tick method.

What can I do to interpolate smoothly between currentYaw and targetYaw, but without the screen moving so fast.

Thank you for all the help!

Please note that I don't need any code, so it doesn't matter if you're answer is based on Forge or MCP. I just need a logic; I can write the code myself.

Again, thank you so much!

EDIT: In my current implementation, I have the following code:

float progress = (cameraInterpolationTimer.getCurrentTicks() + minecraft.timer.elapsedPartialTicks) / cameraInterpolationTimer.getTargetTicks();
minecraft.thePlayer.rotationYaw = (float) Math.toDegrees(InterpolationMath.angleLinearInterpolate((float) Math.toRadians(minecraft.thePlayer.rotationYaw), (float) Math.toRadians(yaw), progress));
minecraft.thePlayer.rotationPitch = (float) Math.toDegrees(InterpolationMath.angleLinearInterpolate((float) Math.toRadians(minecraft.thePlayer.rotationPitch), (float) Math.toRadians(pitch), progress));

The variables pitch and yaw are the rotations that I intend on facing. I also have variables prevPitch and prevYaw, which are set to pitch and yaw at the end of the function. cameraInterpolationTimer is a repeating timer (which is currently at a fixed interval) which gets reset when the difference between yaw and prevYaw is too large (because the target is moving; thus the pitch and yaw variables change each time the function is called). The function getCurrentTicks in the timer returns the amount of time that is passed since the timer was either created or reset. getTargetTicks is just another way of returning the fixed interval that the timer has been set for.

This should be interpolating smoothly to face the target yaw and pitch. It is working, but there is a mild stutter. It is pretty mild, but it is very annoying to look at and can be easily seen. How can I solve this?

Made title more easy to read
Link
Day Trip
  • 75
  • 1
  • 9

How to gradually interpolate smoothly between two yaw rotations less fast in Minecraft MCP/Forge?

Source Link
Day Trip
  • 75
  • 1
  • 9

How to interpolate smoothly between two yaw rotations less fast in MCP/Forge?

I am coding a custom client for Minecraft using MCP. (Please no hate, I'm not making a hacked client!) I have two variables currentYaw which is the current yaw rotation of the player, and targetYaw which is the yaw rotation that I want the player to be looking at. I have a function called lerpAngle and here is the code for it:

public static float lerpAngle(float fromRadians, float toRadians, float progress) {
    float delta = ((toRadians - fromRadians + PI2 + PI) % PI2) - PI;
    return (fromRadians + delta * progress + PI2) % PI2;
}

There is a float in minecraft.timer called elapsedPartialTicks. This variable is always between 0 and 1. Now I want to interpolate between currentYaw and targetYaw so that the transition is smooth. I passed in elapsedPartialTicks as progress but the screen moves way too fast. I am running all this code from the tick method.

What can I do to interpolate smoothly between currentYaw and targetYaw, but without the screen moving so fast.

Thank you for all the help!

Please note that I don't need any code, so it doesn't matter if you're answer is based on Forge or MCP. I just need a logic; I can write the code myself.

Again, thank you so much!