# How to gradually interpolate smoothly between two yaw rotations in Minecraft 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!

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

float progress = (cameraInterpolationTimer.getCurrentTicks() + minecraft.timer.elapsedPartialTicks) / cameraInterpolationTimer.getTargetTicks();


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?

For example, when starting the transition - choose the desired tick duration (e.g. tickDuration = 10 ticks) and store the startedOnTick. Now in the lerp you can lerp with the progress = (currentTick + elapsedPartialTicks - startedOnTick) / tickDuration. This way you will have your transition take more ticks and be longer.
• @DayTrip if the angle changes, you can restart the lerping. You might also want to make tickDuration correlate with the difference between the current and target angles (so that smaller changes take less time to complete) Oct 20 '21 at 5:35