Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

how manually blend to origin

Discussion in 'Cinemachine' started by Kurenaiz, Oct 23, 2018.

  1. Kurenaiz

    Kurenaiz

    Joined:
    Feb 4, 2017
    Posts:
    2
    I'm having a problem with Cinemachine, i have a small vertical deadzone in my camera, but when the camera move inside this deadzone, it stays there. I need that after a while, the camera go back to its origin point, i managed to achieve what i wanted by creating 2 camera, while one is being used, the other is inactive at origin, then when i want to blend to the origin, i switch the cameras, and when the blend ends, i switch again. but now, i have to create 2 cameras for every part of my game that have a different camera. i wonder if there's an easier way to achieve that besides the way i did. maybe a
    cinemachineBrain.BlendToOrigin();
    . i couldn't find any satisfactory answers.

    Thanks for your attention.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,751
    Instead of creating a second camera, you could perhaps make your own "blend to origin" function by doing something like this:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class BlendToOrigin : MonoBehaviour
    7. {
    8.     public bool startBlend;
    9.     public float blendTime = 1;
    10.  
    11.     CinemachineFramingTransposer transposer;
    12.     float savedDeadZoneSize;
    13.     float savedDampTime;
    14.     bool isBlending;
    15.  
    16.     private void Start()
    17.     {
    18.         var vcam = GetComponent<CinemachineVirtualCamera>();
    19.         if (vcam != null)
    20.             transposer = vcam.GetCinemachineComponent<CinemachineFramingTransposer>();
    21.     }
    22.  
    23.     void Update ()
    24.     {
    25.         if (startBlend && !isBlending)
    26.         {
    27.             startBlend = false;
    28.             isBlending = true;
    29.             savedDeadZoneSize = transposer.m_DeadZoneHeight;
    30.             savedDampTime = transposer.m_YDamping;
    31.             transposer.m_DeadZoneHeight = 0;
    32.             transposer.m_YDamping = blendTime;
    33.             StartCoroutine(AdvanceBlend());
    34.         }
    35.     }
    36.  
    37.     IEnumerator AdvanceBlend()
    38.     {
    39.         yield return new WaitForSeconds(blendTime * 1.5f);
    40.         transposer.m_DeadZoneHeight = savedDeadZoneSize;
    41.         transposer.m_YDamping = savedDampTime;
    42.         isBlending = false;
    43.     }
    44. }
    45.  
     
    Kurenaiz likes this.
  3. Kurenaiz

    Kurenaiz

    Joined:
    Feb 4, 2017
    Posts:
    2
    just implemented your solution, worked really well, this opened my mind on how to work with Cinemachine, thank you.
     
    Gregoryl likes this.