Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Quaternion.Lerp problem - CompareApproximately (aScalar, 0.0F)

Discussion in 'Scripting' started by mathiassoeholm, Oct 9, 2012.

Thread Status:
Not open for further replies.
  1. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Hey!

    I'm having a problem with Quaternion.Lerp, which causes two errors.

    Here's the code, it's supposed to rotate my enemy.

    Code (csharp):
    1.  
    2. // Set rotation target
    3. rotationTarget = Quaternion.Lerp(rotationTarget, Quaternion.LookRotation(attackTarget.position - myTransform.position), rotationSpeed * speedFactor * Time.deltaTime);
    4.  
    5. // Rotate
    6. myTransform.rotation = Quaternion.Lerp(myTransform.rotation, rotationTarget, rotationSpeed * speedFactor * Time.deltaTime);
    7.  
    It gives me the following errors

    At line 2 in above:
    CompareApproximately (aScalar, 0.0F)
    UnityEngine.Quaternion:Lerp(Quaternion, Quaternion, Single)

    At line 5 in above
    transform.rotation assign attempt for 'Fangtooth(Clone)' is not valid. Input rotation is { NaN, NaN, NaN, NaN }.
    UnityEngine.Transform:set_rotation(Quaternion)

    Any help is much appreciated, I am pulling my hair out.. There's literally nothing on this problem (Searched Google)
     
    Muchaszewski likes this.
  2. mathiassoeholm

    mathiassoeholm

    Joined:
    Jul 20, 2010
    Posts:
    104
    Okay I found the problem..

    Multiplying with speedFactor made it pop up with the error.. So I removed speedFactor
    I think it was because speedFactor was 0, making the whole expression 0.
     
    WaqasGameDev likes this.
  3. Cawas

    Cawas

    Joined:
    Jan 14, 2010
    Posts:
    121
  4. Gotcab

    Gotcab

    Joined:
    Apr 22, 2017
    Posts:
    6
    LabOSM likes this.
  5. Brogan89

    Brogan89

    Joined:
    Jul 10, 2014
    Posts:
    244
    Hello from the future! We're in 2019 now and this was still helpful :)
     
  6. handfreedude

    handfreedude

    Joined:
    Jan 6, 2020
    Posts:
    1
    2020 and still is.
     
  7. andrew-newmandilfer

    andrew-newmandilfer

    Joined:
    Dec 16, 2015
    Posts:
    6
    Later in 2020, and still is.
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,764
    Please stop necroposting this. Just click like on the post and move on.
     
    WaqasGameDev likes this.
  9. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    I'm having this same issue when I have high time scale values, but I'm not passing 0s as parameters.
     
    Marscaleb likes this.
  10. shol

    shol

    Joined:
    Jun 24, 2015
    Posts:
    1
    2021, still helpful.
     
    marcospgp likes this.
  11. Muchaszewski

    Muchaszewski

    Joined:
    Sep 23, 2015
    Posts:
    15
    There is a simple fix to it if you are having this error, but you should not get to such a situation anyway, but here you go!
    Code (CSharp):
    1. if (rotation.x + rotation.y + rotation.z + rotation.w == 0)
    2. {
    3.     rotation = Quaternion.identity;
    4. }
     
    ysnrik likes this.
Thread Status:
Not open for further replies.