Search Unity

Cinemachine/Timeline to activate Vcam and zoom in on specific animation

Discussion in 'Cinemachine' started by Mad_Mark, Jun 19, 2019.

  1. Mad_Mark

    Mad_Mark

    Joined:
    Oct 30, 2014
    Posts:
    484
    I have watched all kinds of YT and Unity videos and am so confused. All I want to do is set up a virtual camera that will become enabled when my zombie AI character launches a specific attack animation. Everything I have seen has been the opposite way around, making cutscenes that pan between and launch animations, dialogue style. Is this not possible? Is this not an "event driven" camera operation?

    The zombie is a prefab, and will be instantiated at runtime, so I imagine the vcam will have to be part of that prefab so that it can use the "head" transform as its look-at target?

    How do I tell the vcam to enable when the zombie uses the 1 (of 3) attack animations? Animation event with a script? If so, examples or hints available?

    What I am trying to accomplish is, if the zombie launches a bite animation, close up on its face, throw some blood FX on the camera, then zoom back as the animation ends, and return to the game camera.

    All help is greatly appreciated.
    Mark
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Hi Mark,

    Start by setting up your attack vcam with all the effects etc that you describe. You can attach it to your prefab. Then it's just a question of when to bump its priority. There are several ways to do this.

    One way is to go to the source event - the thing that triggers the bite animation in the first place. Can you add an event handler there to start a coroutine that bumps the vcam's priority for a fixed time, then lowers it again? Or, alternatively, just activates the vcam with gameObject.SetActive().

    If that isn't an option, you can write a script that polls the animation state (as StateDrivenCamera does), and take specific action depending on the state, e.g. activate vcam while state==x. You can look at the code in CinemachineSTateDrivenCamera.cs to see an axample of how it polls animation states.