# Quaternion error every time I do Rigidbody.MoveRotation

Discussion in 'Scripting' started by JustJeff, Apr 20, 2015.

1. ### JustJeff

Joined:
Feb 16, 2015
Posts:
84
I get a few hundred of these a second:

Rotation quaternions must be unit length.
UnityEngine.Rigidbody:MoveRotation(Quaternion)

The angles are only set using Quaternion.LookRotation and Quaternion.Slerp...

Is something wrong with this perhaps:
currAngle = Quaternion.Slerp (currAngle, targetAngle, Time.deltaTime * (2f - Quaternion.Angle (transform.rotation, targetAngle) / 120));

I can't figure out why they wouldn't be unit length and I don't see a way to "normalize" them (aren't they by definition unit length anyway?).

Could the floating point stuff be causing problems in Slerp? And how would I fix/change that?

Thanks in advance!

2. ### JustJeff

Joined:
Feb 16, 2015
Posts:
84
Nobody's ever had this problem?

Joined:
Feb 16, 2015
Posts:
84
Bump

4. ### hamsterbytedev

Joined:
Dec 9, 2014
Posts:
353
Please post full code and error message

5. ### Fluzing

Joined:
Apr 5, 2013
Posts:
815
hamsterbytedev likes this.
6. ### poolts

Joined:
Aug 9, 2012
Posts:
110
Did you manage to fix this?

7. ### QuevSingularIT

Joined:
Mar 16, 2016
Posts:
1
I had the same problem, I don't know if it is a solution for you, but it solved the problem for me. The solution might be to instantiate your attribute currAngle in the start fonction. Give it:
"currAngle = new Quaternion(0,0,0,1); "
Bon courage!

unity_dyhfYUF9PIIF4Q likes this.
8. ### NoScopingDude

Joined:
Apr 7, 2016
Posts:
7
I think its becouse quaterniumonly takes units between 0 and 1(floats) and not 0 to 360

9. ### Steven-Walker

Joined:
Oct 27, 2010
Posts:
38
If anyone else runs into this issue, just normalize the quaternion value:
q = q.normalized;

unityunity