- Home /
Lerping Quaternions Results in NaN's
void Start(){
Quaternion MyRotation = Quaternion.Euler (Vector3.zero);
Quaternion LastRotation = MyRotation;
Quaternion tempRot = Quaternion.Lerp(LastRotation, MyRotation, 1);
}
The code above turns up with this debug log:
'CompareApproximately (aScalar, 0.0F) UnityEngine.Quaternion:Lerp(Quaternion, Quaternion, Single)'.
Is there any way to prevent this from happening? My guess is checking some kind of null reference exception for quaternions but I'm not sure what that is. Note: This is a simplified version of my script. Solving the problem in this code will solve the problem in my full code.
There's nothing wrong with this code, save for fact that it's redundant. The result of tempRot will be the same as transform.rotation, so lerping it by any factor would always result in the same factor.
I realize that this is just for the sake of example, so it's probably a moot point.
In any case, the problem has to be somewhere else.
Oh, I guess you're right! I wish there was a debug log for when $$anonymous$$yRotation turned up invalid in my code.
So I combed through my code and printed $$anonymous$$yRotation. I'll change the code above to properly replicate the problem.
Okay, I'm honestly at 100% loss for what to do. I can't reproduce this bug and my script's a bit long. If you don't $$anonymous$$d, would you comb through it?
Answer by jpthek9 · Jan 06, 2015 at 08:04 PM
This is a facepalm moment. I had a return; in my Start method that stopped the rest of the start if the unit was not mine. MyRotation was never assigned.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175745im_/https://answers.unity.com/themes/thub/images/avi.jpg)