Search Unity

Quaternion Rotation Help

Discussion in 'Physics' started by webjeff, Apr 9, 2019.

  1. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    39
    I'm trying to get an object to rotate the way I want to through Quaternions. See my pictures for example, but I can't use Quaternion.LookRotation because that changes the Z rotation of the object and I don't want to do that.

    Pic 1:
    The 'leg/foot' is pointing at my ball using Quaternion.LookRotation. Looks good.


    Pic 2:
    Using Quaternion.LookRotation, notice the foot is not going the right direction, it's going up. This makes sense as to what LookRotation does, but not what I want.
    pic2.png

    Pic 3:
    This is what I want, but I am manually rotating the object so I can show you. Ideally I want to call a function 'GetQuaternionToPointTo(Vector3 pos)'. I need to keep that rotation proper.
    pic3.png

    Any thoughts? I might be able to solve this by changing the UP vector in that function, but does not completely because I want to drag the ball around and see the object correctly rotate and align the way I want.
     

    Attached Files:

    • pic1.png
      pic1.png
      File size:
      48.7 KB
      Views:
      581
  2. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    39
    Nevermind! I figured it out, I had to store the original UP vector to be used with the LookRotation call... Of course!