Hi i have a start point and end point which i use to create some point between, this points are calculated with a blending rotation between point A rotation to point B rotation.
I use Mathf.LerpAngel but still I'm getting wrong result.
When rotation reaches -180 or 180 in some cases even -359.05 or 0.005 it gets flipped. Here's the result with issue : https://raw.githubusercontent.com/CycloneRing/UnityRotationLerp/main/RotationLerpIssue%20.mp4
And this is the result I want to achieve:
And here's my code (Look at Github):
// Extra points for (int i = 0; i < genPts.Count; i++) { float blendValue = ConvertRange(0, genPts.Count, 0.0f, 1.0f, i); var localEulerFrom = start.localEulerAngles; var leftAngleFrom = spt.angleLeft; var rightAngleFrom = spt.angleRight; var localEulerTo = end.localEulerAngles; var leftAngleTo = ept.angleLeft; var rightAngleTo = ept.angleRight; var localEulerBlend = LerpAngles(localEulerFrom, localEulerTo, blendValue); var leftAngleBlend = Mathf.Lerp(leftAngleFrom, leftAngleTo, blendValue); var rightAngleBlend = Mathf.Lerp(rightAngleFrom, rightAngleTo, blendValue); var base_left_angle = Quaternion.Euler(localEulerBlend.x, localEulerBlend.y, localEulerBlend.z + leftAngleBlend) * Vector3.right; var base_right_angle = Quaternion.Euler(localEulerBlend.x, localEulerBlend.y, localEulerBlend.z + -rightAngleBlend) * Vector3.right; var leftPos = genPts[i] + -base_left_angle.normalized * length; var rightPos = genPts[i] + base_right_angle.normalized * length; genExtraPts.Add(leftPos); genExtraPts.Add(rightPos); } I want it continuously keep rotation with a smooth blend. How can i achieve that?
A simple, minimal unity project is uploaded in github at https://github.com/CycloneRing/UnityRotationLerp
EDIT 1 : I tried using Quaternion as well but result is same.
// Extra points for (int i = 0; i < genPts.Count; i++) { float blendValue = ConvertRange(0, genPts.Count, 0.0f, 1.0f, i); var rotationFrom = start.localRotation; var rotationTo = end.localRotation; var localRotationBlend = Quaternion.LerpUnclamped(rotationFrom, rotationTo, blendValue); var base_left_angle = localRotationBlend * Vector3.right; var base_right_angle = localRotationBlend * Vector3.right; var leftPos = genPts[i] + -base_left_angle.normalized * length; var rightPos = genPts[i] + base_right_angle.normalized * length; genExtraPts.Add(leftPos); genExtraPts.Add(rightPos); } 