Search Unity

Quaternion error every time I do Rigidbody.MoveRotation

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

  1. JustJeff

    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

    JustJeff

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

    JustJeff

    Joined:
    Feb 16, 2015
    Posts:
    84
  4. hamsterbytedev

    hamsterbytedev

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

    Fluzing

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

    poolts

    Joined:
    Aug 9, 2012
    Posts:
    113
    Did you manage to fix this?
     
  7. QuevynR

    QuevynR

    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! ;)
     
  8. NoScopingDude

    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

    Steven-Walker

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