Search Unity

Cinemachine with animations and freelook

Discussion in 'Cinemachine' started by M_Keyla_M, May 27, 2020.

  1. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    Hello!
    At the moment im using the following script for my character movement
    However what i want is for the camera to follow the character and to have a freelook option. I've been refered to a couple cinemachines like the Free look one but that won't let me use my animations. I've also tried the state camera (which lets me use animations) but that doesn't have a free look option.
    What can i do to fix this (im a noob when it comes to scripting, this script is from the JohnLemon projected ):

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CharacterMovement : MonoBehaviour
    6. {
    7.     public float turnSpeed = 20f;
    8.  
    9.     Animator m_Animator;
    10.     Rigidbody m_Rigidbody;
    11.     Vector3 m_Movement;
    12.     Quaternion m_Rotation = Quaternion.identity;
    13.  
    14.     void Start ()
    15.     {
    16.         m_Animator = GetComponent<Animator> ();
    17.         m_Rigidbody = GetComponent<Rigidbody> ();
    18.     }
    19.  
    20.     void FixedUpdate ()
    21.     {
    22.         float horizontal = Input.GetAxis ("Horizontal");
    23.         float vertical = Input.GetAxis ("Vertical");
    24.        
    25.         m_Movement.Set(horizontal, 0f, vertical);
    26.         m_Movement.Normalize ();
    27.  
    28.         bool hasHorizontalInput = !Mathf.Approximately (horizontal, 0f);
    29.         bool hasVerticalInput = !Mathf.Approximately (vertical, 0f);
    30.         bool isWalking = hasHorizontalInput || hasVerticalInput;
    31.         m_Animator.SetBool ("IsWalking", isWalking);
    32.  
    33.         Vector3 desiredForward = Vector3.RotateTowards (transform.forward, m_Movement, turnSpeed * Time.deltaTime, 0f);
    34.         m_Rotation = Quaternion.LookRotation (desiredForward);
    35.     }
    36.  
    37.     void OnAnimatorMove ()
    38.     {
    39.         m_Rigidbody.MovePosition (m_Rigidbody.position + m_Movement * m_Animator.deltaPosition.magnitude);
    40.         m_Rigidbody.MoveRotation (m_Rotation);
    41.     }
    42. }
    43.  
    44.  
     
  2. M_Keyla_M

    M_Keyla_M

    Joined:
    Dec 24, 2014
    Posts:
    57
    I Fixed it!!!! don't know how to delete a thread sorry...