Hello i’ve a begin level and finish level which i take advantage of to create some level between, this factors are calculated with a mixing rotation between level A rotation to level B rotation.
I take advantage of Mathf.LerpAngel however nonetheless I am getting unsuitable end result.
When rotation reaches -180 or 180 in some instances even -359.05 or 0.005 it will get flipped.
Here is the end result with subject : https://uncooked.githubusercontent.com/CycloneRing/UnityRotationLerp/principal/RotationLerpIssuepercent20.mp4
And here is my code (Take a look at Github):
// Additional factors
for (int i = 0; i < genPts.Rely; i++)
{
float blendValue = ConvertRange(0, genPts.Rely, 0.0f, 1.0f, i);
var localEulerFrom = begin.localEulerAngles;
var leftAngleFrom = spt.angleLeft;
var rightAngleFrom = spt.angleRight;
var localEulerTo = finish.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.proper;
var base_right_angle = Quaternion.Euler(localEulerBlend.x, localEulerBlend.y, localEulerBlend.z + -rightAngleBlend) * Vector3.proper;
var leftPos = genPts[i] + -base_left_angle.normalized * size;
var rightPos = genPts[i] + base_right_angle.normalized * size;
genExtraPts.Add(leftPos);
genExtraPts.Add(rightPos);
}
I need it constantly preserve rotation with a clean mix.
How am i able to obtain that?
A easy, minimal unity venture is uploaded in github at https://github.com/CycloneRing/UnityRotationLerp
EDIT 1 : I attempted utilizing Quaternion as effectively however result’s identical.
// Additional factors
for (int i = 0; i < genPts.Rely; i++)
{
float blendValue = ConvertRange(0, genPts.Rely, 0.0f, 1.0f, i);
var rotationFrom = begin.localRotation;
var rotationTo = finish.localRotation;
var localRotationBlend = Quaternion.LerpUnclamped(rotationFrom, rotationTo, blendValue);
var base_left_angle = localRotationBlend * Vector3.proper;
var base_right_angle = localRotationBlend * Vector3.proper;
var leftPos = genPts[i] + -base_left_angle.normalized * size;
var rightPos = genPts[i] + base_right_angle.normalized * size;
genExtraPts.Add(leftPos);
genExtraPts.Add(rightPos);
}