Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

LookRotation Zero: but why?

Discussion in 'Scripting' started by Inxentas, Jan 20, 2020.

  1. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    132
    Why does Quaternion.LookRotation() throw a warning when the result is zero?

    Code (CSharp):
    1. Look rotation viewing vector is zero
    2. UnityEngine.Quaternion:LookRotation(Vector3)
    Is zero not a valid rotation to look at? If one would look at zero, does ZERO stare back or something? I don't get why this is considered a result Unity must warn me about. What if I'm fine with the lookRotation being zero?

    Look at zero all you want, PlayerAvatarScript! I honestly don't care. Why does Unity?
     
  2. _met44

    _met44

    Joined:
    Jun 1, 2013
    Posts:
    551
    Hey, that parameter is a direction, not a world positon or such.

    If it helps try to picture your face pointing at no direction whatsoever, unless you're some sort of mist thats not possible and your face is pointing at something. Same goes for LookRotation(), if you want to to perform the calculation you need to give it proper input.. And if you want to reset the rotation, then use the Quaternion.Identity property instead of LookRotation(Vector3.zero) !
     
  3. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    132
    I think I understand. But no, I just wanted object A to face object B regardless of their respective positions. I wanted a Rigidbody to tell another Gameobject which way to face. I think the issue in my case is that I fed the the lookRotation method the velocity of a Rigidbody, which can be zero. If I surround the code with an IF statement that checks if velocity is not zero, I still get errors when velocity is minute. It's my guess that the method rounds to zero internally to express a Quaternion.

    (I was basicly just trying to get a GameObject to act as the "Avatar" for the player, while the actual control is done with a Sphere. I'm still looking for the best way to get a Quaternion based on movement alone since there is no actual GameObject to get a position from. The position is basicly an arbitary number of units "ahead" if you catch my drift).
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    7,249
    When your look vector is 0, set it to forward.

    With direction vector 0, you may run into multiple issues in future, just as quaternion case.
     
unityunity