Skip to content

Instantly share code, notes, and snippets.

@UtMan88
Last active October 4, 2021 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UtMan88/1a2126e276a07a1bcd3a13069dc569a9 to your computer and use it in GitHub Desktop.
Save UtMan88/1a2126e276a07a1bcd3a13069dc569a9 to your computer and use it in GitHub Desktop.
Originally posted by BakonGuy at Unity Answers: https://answers.unity.com/questions/775784/lerping-euler-angles-make-entire-spin.html, this script helps lerp around angles that potentially pass into the negatives, which would cause objects to spin rapidly.
//Properly Lerp between two angles
Vector3 AngleLerp(Vector3 StartAngle, Vector3 FinishAngle, float t)
{
float xLerp = Mathf.LerpAngle(StartAngle.x, FinishAngle.x, t);
float yLerp = Mathf.LerpAngle(StartAngle.y, FinishAngle.y, t);
float zLerp = Mathf.LerpAngle(StartAngle.z, FinishAngle.z, t);
Vector3 Lerped = new Vector3(xLerp, yLerp, zLerp);
return Lerped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment