I Everyone, i’m stuck with an error since a wile now and i hope one of you have a solution for me.
Here is my code :
private void lookTarget(Vector3 pos){
Quaternion newRotation = Quaternion.LookRotation(transform.position - pos, Vector3.down);
newRotation.x = Quaternion.identity.x;
newRotation.z = Quaternion.identity.z;
transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, Time.deltaTime * 10);
}
And it give me sometimes this error :
!CompareApproximately (aScalar, 0.0F)
UnityEngine.Quaternion:Lerp(Quaternion, Quaternion, Single)
I Try to found an answer on internet but without succes. If someone have the solution it will help me a lot.
Thank’s everyone.
You probably have a (0, 0, 0, 0) Quaternion in either end of the lerp.
PS: I know this is an old question, but it was #2 in my Google search results.
In places you can get a Quaternion(0,0,0,0), just normalize it
Quaternion(0,0,0,0).normalized == Quaternion(0,0,0,1) == Quternion.identity
Fixes this error, changes nothing.
I hope so.
I’m useing a lot of rotation * Quaternion.Inverse(prevRotation) to get a delta of two rotations, and in one place it bit me in my ( )( ), but normalization fixes it.
The error happens when the third parameter is larger than 1 . Try to change transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, Time.deltaTime * 10);
by
float t = Mathf.Clamp(Time.deltaTime * 10, 0f, 0.99f);
transform.rotation = Quaternion.Lerp(transform.rotation, newRotation, t);