Thanks for the replies!
It seems like there are 2 functions that deal with Angle interpolation, SmoothDampAngle() and LerpAngle(). Functions like slerp interpolates a ‘value’, not an ‘angle’. SmoothDampAngle() looks like the most flexible option.
So, now I have the player rotating correctly, but I have 2 strange, what appears to be, bugs. Here is my function.
void RotateMe(float rotateYTarget)
{
if(Mathf.Abs(myGeometry.transform.eulerAngles.y) == rotateYTarget)
return;
The function is called every frame so I check to see if the player is already in the correct rotation (the function that calls this one handles the player movement). No need for extra function calls down below. This works fine for anything between 360 and 225 degrees, and 135 for some reason. Whenever I rotate to 180, 90 and 45 degrees, this if statement somehow returns false. I even output the result to the console, and it displays “180 Rotating to 180”.
Debug.Log(myGeometry.transform.eulerAngles.y + " Rotating to " + rotateYTarget);
So, both values are equal, yet it somehow returns false if I compare the two in the if statement, so the Debug.Log message is displayed every frame. It should only display every frame while the player is rotating.
The rest of the function.
rotateTowardsProgess = Mathf.SmoothDampAngle(myGeometry.transform.eulerAngles.y, rotateYTarget, ref nill, rotateTowardsTargetInSeconds);
if(Mathf.Abs(myGeometry.transform.eulerAngles.y - rotateYTarget) < 0.2f)
rotateTowardsProgess = rotateYTarget;
myGeometry.transform.eulerAngles = new Vector3 (0f, rotateTowardsProgess, 0f);
}
When I rotate to 90 or 45 degrees, it never goes to 90 or 45 but stops at 90.00001 and 45.00001. I can understand that these values don’t return true when compared to the target value.
My questions then are:
-
Why don’t the numbers settle at 90 and 45 degrees? I snap the result from the SmoothDampAngle function to the target amount if the difference is less than 0.2.
-
Why does the if statement return false when I compare 2 values (180 and 180) that are the same according to the console output.