Search Unity

Cinemachine access Animated Target through code

Discussion in 'Cinemachine' started by nlv22, Nov 12, 2018.

  1. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    How can I access the Animated Target property for the state-driven Cinemachine camera? It saids that Cinemachine does not contain the definition for it. My player that has the Animator component gets spawn into the game.

    If you see my code below where my comment is at:

    Code (CSharp):
    1.     private GameObject tPlayer;
    2.     private Animator tPlayerAnimator;
    3.     public Transform tFollowTarget;
    4.     private CinemachineVirtualCamera vcam;
    5.     private GameObject NavTarget;
    6.  
    7.  
    8.     void Start()
    9.     {
    10.         vcam = GetComponent<CinemachineVirtualCamera>();
    11.         NavTarget = GameObject.FindWithTag("NavTarget");
    12.     }
    13.  
    14.  
    15.     void Update()
    16.     {
    17.         if (tPlayer == null)
    18.         {
    19.             tPlayer = GameObject.FindWithTag("Player");
    20.             tPlayerAnimator = GameObject.FindWithTag("Player").GetComponent<Animator>();
    21.  
    22.             if (tPlayer != null)
    23.             {
    24.                 tFollowTarget = tPlayer.transform;
    25.                 vcam.LookAt = tFollowTarget;
    26.                 vcam.Follow = tFollowTarget;
    27.                 vcam.AnimatedTarget = tPlayerAnimator; // How to access the Animated target?
    28.  
    29.      
    30.                 NavTarget.transform.parent = tPlayer.transform;
    31.             }
    32.  
    33.  
    34.         }
    35.     }
     
    Gregoryl likes this.
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You want to use CinemachineStateDrivenCamera vcam, and then you'll have vcam.m_AnimatedTarget
     
  3. nlv22

    nlv22

    Joined:
    Dec 20, 2016
    Posts:
    31
    Thanks. That works!