Search Unity

Blending Between ClearShots

Discussion in 'Cinemachine' started by ProtonOne, Jul 22, 2017.

  1. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I made a simple scene with 2 ClearShot managers:


    I have a small script that toggles the GameObject.SetActive to only have 1 Clear Shot manager visible at a time:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CameraManager : MonoBehaviour {
    4.  
    5.     public GameObject ClearShotAGO;
    6.     public GameObject ClearShotBGO;
    7.  
    8.     private void Start() {
    9.         // Start out with ClearShot A Active
    10.         ClearShotAGO.SetActive(true);
    11.         ClearShotBGO.SetActive(false);
    12.     }
    13.  
    14.     void Update () {
    15.  
    16.         // Swithc To ClearShot A
    17.         if( Input.GetKeyDown(KeyCode.A) ) {
    18.             ClearShotAGO.SetActive(true);
    19.             ClearShotBGO.SetActive(false);
    20.         }
    21.  
    22.         // Switch To ClearShot B
    23.         if( Input.GetKeyDown(KeyCode.B) ) {
    24.             ClearShotAGO.SetActive(false);
    25.             ClearShotBGO.SetActive(true);
    26.         }
    27.     }
    28. }
    29.  
    This causes a blending problem, it causes the blend origin to be from the position (0,0,0).
    GIF: https://gfycat.com/MammothGregariousAlabamamapturtle

    You can see it flying from the origin to the new Clear Shot camera when I change the active Clear Shot. I have the sphere & cube at around world position (0,0,1000).

    Solution 1
    I can get it to blend nicer if I comment out the following in CinemachineClearShot.UpdateCameraState Ln 168:
    Code (CSharp):
    1.             //else
    2.             //    m_State =  CameraState.Default;
    GIF: https://gfycat.com/UnknownUncommonCoot

    Then the ClearShotManager remembers it's previous state instead of instantly forgetting it when it gets set Inactive, allowing the blend to work.

    Solution 2
    Another idea I had was only having 1 root ClearShot and creating a tree of VirtualCameras below it that I could enable and disable. But ClearShot explicitly only takes 1st level children. Allowing it to take all children would probably work too. But blending between multiple ClearShot managers seems more flexible.

    Solution 3
    Use Priority to switch between the ClearShots. Then only switch the low priority ClearShot off after the blend is complete. This is what I currently do since it requires no changes to Cinemachine, but it is kind of ugly. I want to completely turn off the inactive clear shot to save from doing the Raycasts on the CinemachineCollider since they are not being used at all (performance consideration).

    This problem likely has a similar aim to this thread:
    Force ClearShot to change cameras?

    My main goal is to be able to dynamically switch between ClearShot styles (chase cam, from player cam, overview cam, etc.). It feels less jarring when the ClearShot cuts happen between similar shot styles. Then I can manually rotate between different styles every 10 seconds.

    I'm using Unity Version 2017.1.0f3 & Cinemachine 2.0.1. I can always submit this project as a bug if it seems like a bug, or maybe I am approaching the problem wrong?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @Doug-Wolanick Thanks for the post! I think you're onto a genuine issue in CM. Your fix #1 comes close to fixing it but my sense is that it might run a little deeper. Would you mind zipping up this project and posting it here?
     
  3. ProtonOne

    ProtonOne

    Joined:
    Mar 8, 2008
    Posts:
    406
    I've attached the project to this post.
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @Doug-Wolanick The fix will be in the next CM point release. Thanks for the post.
     
    ProtonOne likes this.