Search Unity

MoveRotation (Quaternion) Overtime

Discussion in 'Scripting' started by tezer86, Mar 11, 2015.

  1. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Hey Guys,

    I am having an issue with MoveRotation for a rigidbody snapping to the new Quaternion instead of over time. I can't *Time.deltaTime as this throws an error.

    Code below is:

    Code (CSharp):
    1.         //Vector2 directionToFace;
    2.         Vector3 faceTarget = new Vector3 (directionFromThumb.x,0,directionFromThumb.y);
    3.  
    4.  
    5.         Quaternion newRotation = Quaternion.LookRotation (faceTarget);
    6.         playerRig.MoveRotation(newRotation *Time.deltaTime);
    7.    
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    A Quaterion * a float is undefined. You probably want to use a lerp.
     
  3. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Thanks for the reply, I will give that a go.
     
  4. tezer86

    tezer86

    Joined:
    Jul 19, 2010
    Posts:
    90
    Thanks again for the help, here is my final code for anyone that has the same issue:

    Code (CSharp):
    1.         //Vector2 directionToFace;
    2.         Vector3 faceTarget = new Vector3 (directionFromThumb.x,0,directionFromThumb.y);
    3.  
    4.         Quaternion currentRotation = playerRig.rotation;
    5.         Quaternion newRotation = Quaternion.LookRotation (faceTarget);
    6.         playerRig.MoveRotation(Quaternion.Slerp (currentRotation, newRotation, 0.4f));

    I now take the players current position and Slerp between the that and the new position from the thumbstick