Search Unity

Cinemachine Transposer smooth zoom. Help please

Discussion in 'Cinemachine' started by elfnik, Sep 29, 2020.

  1. elfnik

    elfnik

    Joined:
    Feb 3, 2018
    Posts:
    8
    Hi guys

    I`ve been using cinemachine for quite a while and it is AWESOME literally in any mean. The only addon I am using and it is worth.

    However, without further chatter i want to explain the problem I have, it is simple one i guess but i can't find the proper way to do it. I am making 2.5D game - sidescroller, going left and right only, so far I got everything under control, the only problem i have is I cant make the zoom functionality to work smoothly, it works, but the transition is very fast and i need slow transitions.

    I am using only 1 camera attached to the main character which is following him everywhere. I have referenced parts of the cinemachine code/transposer functions to an invisible blocks(trigger) through my map and once the player collides with it, it updates the Vcam values with the new ones from the colliding block.

    For the zoom function I am trying to manipulate the "Camera Distance". I have also tried playing with "Field of view" setting so i can zoom, but the result is the same, the zoom transition is happening very fast.

    I have noticed that when dragging the "Camera Distance" field, the camera is transitioning smoothly, but if I write a number inside the field the transition goes very rough and fast. So please help and if someone can explain me how can i use the "drag" transition (if possible) which smooths out the zoom, or is there other feature that can be accessed through code?

    Thank you.

    So i am using this setup for the main camera:
    upload_2020-9-29_11-51-3.png

    I am using this setup for Vcam1:
    upload_2020-9-29_11-59-58.png
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Standard practice in Cinemachine is to create separate vcams with the different settings, then allow the CM brain to blend when you activate the new vcam. Then you can adjust blend time and style easily.

    However, you are are doing it differently: you are directly changing the settings in the same vcam. The vcam will respond instantly to settings changes, so you will have to write some code to lerp the change in over time (perhaps with a coroutine).
     
    Flying_Banana and elfnik like this.
  3. elfnik

    elfnik

    Joined:
    Feb 3, 2018
    Posts:
    8
    Thank you for the help, i had troubles before writing lerp function code, it wasn't working (probably i did some wrong things, i`m still learning programming) but thank you for the idea.

    Update:
    I followed your idea and actually i made it. THANK YOU!!!
    Here is what i did, pretty simple (if i could knew this before), it is working:

    zoomLevel -> value that i add in the inspector manually

    if (transposer.m_CameraDistance < zoomLevel)
    {
    transposer.m_CameraDistance = transposer.m_CameraDistance + Time.deltaTime;
    if (transposer.m_CameraDistance == zoomLevel)
    {
    return;
    }
    }
    else if (transposer.m_CameraDistance > zoomLevel)
    {
    transposer.m_CameraDistance = transposer.m_CameraDistance - Time.deltaTime;
    if (transposer.m_CameraDistance == zoomLevel)
    {
    return;
    }
    }


    I also wrote custom code for rotation for cinemachine camera and works like charm. I`m sure this will help many people as well:

    targetRotation = value that i add in the inspector manually
    rotateVertical = the angle Y i add in the inspector manually
    rotateHorizontal = the angle X i add in the inspector manually
    smoothing = multiplier of the movement, i add in the inspector manually

    void Update()
    {
    targetRotation = Quaternion.Euler(rotateVertical, rotateHorizontal, 0);
    transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, smoothing * accelerationValue * Time.deltaTime);
    }



    Thank you once again