Search Unity

Question Root motion - turning character to the cameras look direction

Discussion in 'Animation' started by CryptoJanne, May 31, 2020.

  1. CryptoJanne

    CryptoJanne

    Joined:
    Jul 7, 2019
    Posts:
    12
    Hello everybody, I have decided to try out root motion! I have an issue though that i have googled around for HOURS trying to find.

    I can control my character using
    Code (CSharp):
    1.  
    2. vertical = Input.GetAxis("Vertical");
    3. horizontal = Input.GetAxis("Horizontal");
    4.  
    and then feed it to the animator
    Code (CSharp):
    1.  
    2. animator.SetFloat("Horizontal", horizontal);
    3. animator.SetFloat("Vertical", vertical);
    4.  
    but that does move the character totally unrelated to the camera look position. I want the character to turn and move towards where the camera is looking and i cannot figure out how i can get a float value between 1 and -1 that i can feed the animator.

    Any help deeply appreciated!