Search Unity

Quaternion snapping back to original rotation?

Discussion in 'Scripting' started by GladGoblinGames, Dec 12, 2015.

  1. GladGoblinGames

    GladGoblinGames

    Joined:
    Dec 14, 2011
    Posts:
    118
    Okay, so basically, if the player enters a trigger object, it is meant to smoothly look at the object the noise came from. Problem is, after it has done this, the rotation goes back to its original rotation before the Quaternion was activated. I want it to carry on from the rotation that the Quaternion left off at.

    This is the rotation I have...

    Code (CSharp):
    1. player.transform.rotation = Quaternion.Lerp(player.transform.rotation, Quaternion.LookRotation(objectToRotateTowards.transform.position -  player.transform.position), Time.deltaTime * 10f);
    And this might help as well..

    This is the function that is called...

    Code (CSharp):
    1.     IEnumerator PlayerReaction()
    2.     {
    3.         Debug.Log("Player reaction called");
    4.  
    5.         player.GetComponent<CharacterController>().enabled = false;
    6.  
    7.         firstPersonController.enabled = false;
    8.  
    9.         reactionPlayerActive = true;
    10.  
    11.         yield return new WaitForSeconds(2.0f);
    12.  
    13.         Debug.Log("Seconds are over!!!!!!");
    14.  
    15.         reactionPlayerActive = false;
    16.  
    17.         player.GetComponent<CharacterController>().enabled = true;
    18.  
    19.         firstPersonController.enabled = true;
    20.  
    21.         firstPersonController.transform.rotation = player.transform.rotation;
    22.  
    23.         Destroy(this.gameObject);
    24.     }
     
  2. tranos

    tranos

    Joined:
    Feb 19, 2014
    Posts:
    180
    You could store the rotation in a Vector3.
     
  3. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    why convert it? just store the original quaternion before you do the update to look at the object.