Search Unity

Integration with existing camera script

Discussion in 'Cinemachine' started by dadude123, Nov 28, 2017.

  1. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    Hello,
    I'm wondering how easy it is to integrate cinemachine virtual cameras with an existing camera script.

    Right now I have a script on my camera that handles all positioning and rotation ("attaching" to a character, avoiding geometry, ...).

    Now let's say I'd want to start a cutscene where the camera should move to a predefined location; would I have to disable my own camera script?

    I would like to avoid having to disable my own camera script for various reasons and I wondered if there was a way to bypass the problem like this:

    I'd change make my camera script so it controls a virtual camera instead of the real one,
    then I could interpolate the real camera (the gameobject with the actual rendering camera component on it) between vcam1 and vcam2 (my cutscene).

    Is that possible? Can I just assign values to a virtual camera like that?

    Or is there a better way to do this that wouldn't require me changing my camera script at all?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You're on the right track. Have your script control a virtual camera instead of the Unity Camera. Set up the virtual camera logic to "Do nothing" for both Aim and Body, and it won't interfere with whatever you put in its transform. Once it's a virtual camera, it will play nicely with the rest of Cinemachine (i.e. blends, post-processing, etc).

    You can even do this without changing your script at all. Just add the CinemachineVirtualCamera component to the same game object that currently holds the Unity Camera that the script controls, and then disable the Unity camera. Your script doesn't even have to know that it's controlling a vcam.
     
    dadude123 likes this.