Search Unity

Changing camera properties by trigger

Discussion in 'Cinemachine' started by malyKuba, Jul 2, 2018.

  1. malyKuba

    malyKuba

    Joined:
    Jan 30, 2013
    Posts:
    6
    Hi there,
    we are using Cinemachine in our 2.5D game and I am wondering how I can smoothly change properties of camera during the real game (no timeline). Let's say distance and Screen Y when some event is triggered. I know that I can have more vcams and blend between them by changing priorities by I am pretty sure that our artist will require more freedom than few predefined cameras.
    Let's say that character is in cave and camera is pretty close, now he is going to larger cave so came will zoom out little bit and then he is going to open space world so camera will zoom out even more for spectacular scenery. In the scene will be tons of various environments where different distances (and other camera's properties) will be required. I would imagine some triggers and component on it with settings of camera and blend parameters, because otherwise we will end with huge amount of vcams in scene. Is something like this possible or should I write some homemade solution? Thanks for the respond in advance,

    Jakub.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,522
    All of the Cinemachine fields are accessible by script. For instance, to change a vcam composer's screen Y you would do this:
    Code (CSharp):
    1. var composer = vcam.GetCinemachineComponent<CinemachineComposer>();
    2. composer.m_ScreenY = bla;
    See the Scripting scene in CinemachineExamples for some sample code. Note that you will have to change these values gradually or there will be a pop. Another option might be to generate a dynamic vcam from code, set the params you want, then use blending to blend to it.
     
  3. malyKuba

    malyKuba

    Joined:
    Jan 30, 2013
    Posts:
    6
    Yeah, I am aware that I can change fields from script, but I would miss nice blending of Cinemachine. There is lot of field to blend and I am not talking about post processing yet, so I am not so enthusiastic to change every property, that artist will come up with, gradually. So I guess creating dynamic vcam can make a trick. Or maybe pool of 2 vcams and change theirs properties and then use their blending... Anyway thx, for the advice :).
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,522
    Don't worry about creating lots and lots of vcams. They consume little or no resources while they are inactive. Activate the one you need when the player enters a trigger zone, and deactivate the old one at the same time. Blending will be free and automatic (even when the outgoing vcam is inactive).

    The nice thing about this method is that you're enabling your artist to do the whole thing! It's a very powerful approach to the solving the problem.
     
unityunity