- Home /
Quaternion.Lerp is not working ,causing weird rotations
Here the part of the code that deals with rotation(no error, just weird rotation are produced, a back and forth rotation in just 1 degree);
while (main.transform.position!= new Vector3(5,5,5)&& main.transform.rotation!=Quaternion.Euler(new Vector3(0,-180,0))){
main.transform.position=Vector3.Lerp (main.transform.position,new Vector3(5,-10,-5),Time.deltaTime);
main.transform.rotation=Quaternion.Lerp (transform.rotation,Quaternion.Euler(new Vector3(0,-180,0)),Time.deltaTime*5);
yield return null;
}
yield return null;
}
Can anyone tell me what wrong or can anyone tell me a better approach to deal with when switching rotations;
A common beginner mistake is to lerp between the current value and the target value. Lerping occurs between two fixed points, such as an initial value and a target value. Ex:
Vector3 initialPosition = transform.position;
Vector3 targetPosition = transform.position + new Vector3(5,5,5);
while (!isDone)
{
transform.position = Vector3.Lerp(initialPosition, targetPosition, SO$$anonymous$$E_LERP_VALUE);
yield return null;
}
transform.position = targetPosition;
A common beginner mistake is to lerp between the current value and the target value.
@iwaldrop - not true. Lerping from the current value to the end value is a non-traditional use of Lerp, but when used this way, produces an eased rotation. @UnityDevelopper - Note I always use Slerp for this particular rotation.
fix it thanks for anyone who answers, i really just need to use Quaternion.RotateTowards