Search Unity

Changing follow target in 2D

Discussion in 'Cinemachine' started by OtakuD, May 2, 2019.

  1. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Hi Peeps, still new to Cinemachine and would like to know how others are handling switching camera targets in 2D? The ortho size of my camera and confined bounds are all set on level load to the main camera and I hear you are meant to use virtual cams as blends but this seems rather cumbersome as then I have to change all virtual cams to use the same confiner, ortho zoom, framing etc to maintain pixel perfect views, is this really the best way to do so?

    Perhaps I have to write my own script to unset a follow target, lerp to the next target position and then follow that target?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    With Cinemachine, you never set anything on the main camera directly. Instead, you create a virtual camera, and load your settings to there, as if it were the main camera. The main camera will take its settings and position automatically from the current active virtual camera at all times.

    Once you have that paradigm set up, you can create other virtual cameras with different settings. They will remain passive until they are made the current active vcam (either by object activation or by raising their priority). At that point, the main camera will blend into its new settings, as defined by the new vcam.

    Different vcams can have different procedural positioning settings, and by switching between them, the main camera can be given arbitrarily complex behaviour by building it up with simple pieces.

    Does that make sense?
     
  3. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Does make sense, but how would one switch to another vcam that retains ortho zoom (and pixel perfection) as well as framing and confinement information so that all vcams maintain consistency? When switching a vcam on and off it often zooms in/out or has it's own default framing (which is different to my main vcam), are there simple ways to clone all these lens and extensions etc between each vcam without having to do them manually per instance?

    I really just want one vcam setup a very specific way to switch between various targets in my scene. i.e. when talking to an NPC to transition smoothly from the player to the NPC without the instant shift a follow change seems to make.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You'll have to write a little init script to iterate through the vcams in the scene and set the relevant settings according to a template.
     
  5. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Ok thanks, I'd prefer to just lerp the vcam to the target and then set it since I could add more extensions later which makes cloning an unknown number of them troublesome.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    Consider having an invisible GO that serves as target, which you lerp between your actual targets, parenting them once they get there. Then the target can stay constant on the vcams.

    Or, you can use a CM target group and lerp the members' weights to change focus.
     
    Last edited: May 2, 2019
  7. OtakuD

    OtakuD

    Joined:
    Apr 24, 2014
    Posts:
    49
    Aah ok that's not a bad idea, I guess it's not a good idea to manually move vcams? Would I do the same thing if I wanted to move the camera around in a timeline cutscene scenario without a target? Thanks for the help.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    You can't manually move the vcams unless you turn off their procedural positioning components. Easier to just move a fake target around.

    No problem manually moving the vcams from timeline or script or parenting, so long as you're not also telling them to move themselves. Putting "Do Nothing" in Aim and Body will turn off the procedural positioning and orientation, so that you can manipulate the vcam's transform without obstruction.

    Note that, even if you're positioning the vcam manually, you can still have CM good stuff like Noise and Impulse and Confiner and Collider and blending, as they do not touch the vcam's transform.
     
    OtakuD likes this.