Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dynamic starting and ending point of a cutscene

Discussion in 'Cinemachine' started by nooxouille, Jul 8, 2020.

  1. nooxouille

    nooxouille

    Joined:
    Aug 29, 2018
    Posts:
    24
    Hi!


    I am working on a 3D configurator for outside props.
    Using FlowCanvas, I have created a scene in which I rotate around a static 3D model, using the mouse.
    The zoom is handled by a Z-axis translation of the main camera itself.

    Using Cinemachine and Timeline, I have set up a cutscene with 5 virtual cameras, moving around the static 3D model. The start position (Virtual Camera 1) is the same as the ending position (Virtual Camera 5).
    The CinemachineBrain is located on a sub camera, configured to hide GUI elements.
    I am also using a homemade script to cancel any input from the user while the cutscene is playing.

    When pressing "P", the Timeline start and so is the cutscene.

    The problem I am facing is that I want the actual position of the main camera, when pressing "P", to be both the starting and ending point of the cutscene.


    I might haven't search the right way, and I am kinda block on this one. I tried to "cheat" a little, trying to set up fade in/out but I've messed myself up with it and end up here, asking for what I think to be the most flexible solution.

    A short video to illustrate my words


    The sub camera object
    sub_camera.png

    The Timeline
    timeline.png

    The StartCinematicMode.cs

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.Playables;
    4. using FlowCanvas;
    5.  
    6. public class StartCinematicMode : MonoBehaviour
    7. {
    8.    #region Cinematic Logic
    9.    [SerializeField] FlowScriptController rotationFlowController;
    10.    [SerializeField] FlowScriptController cameraFlowController;
    11.  
    12.    [SerializeField] private GameObject mainCamera;
    13.    [SerializeField] private PlayableDirector myDirector;
    14.    #endregion
    15.  
    16.   private void Start()
    17.    {
    18.       rotationFlowController = mainCamera.GetComponent<FlowScriptController>();
    19.       cameraFlowController = mainCamera.GetComponent<FlowScriptController>();
    20.    }
    21.  
    22.  
    23.    private void Update()
    24.    {
    25.       if (Input.GetKeyDown(KeyCode.P))
    26.       {
    27.          StartCoroutine(PlayCutScene());
    28.       }
    29.    }
    30.  
    31.    IEnumerator PlayCutScene()
    32.    {
    33. //      disable rotation logic
    34.        rotationFlowController.enabled = false;
    35.        cameraFlowController.enabled = false;
    36.      
    37. //      disable the main camera
    38.        mainCamera.SetActive(false);
    39.      
    40.        myDirector.Play();
    41.  
    42. //      wait for the timeline sequence to end
    43.        yield return new WaitUntil(() => myDirector.state == PlayState.Paused);
    44.      
    45.        mainCamera.SetActive(true);
    46.        rotationFlowController.enabled = false;
    47.        cameraFlowController.enabled = true;
    48.    }
    49. }
    50.  
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Put a passive CinemachineVirtualCamera behaviour on the main camera (by passive I mean Aim and Body set to DoNothing). Give this vcam higher than default priority. This way, when you activate the subcamera with the CM Brain, it will take on the exact position of the main camera. That is your default CM camera.

    Next, in the timeline, set the ease-in time for your first CM shot to be non-zero. This will make that shot blend in from the default camera. Similarly, set the ease-out time of the last CM clip to non-zero, and it will blend back into the default CM camera at the end.

    upload_2020-7-8_17-48-43.png
     
    nooxouille likes this.
  3. nooxouille

    nooxouille

    Joined:
    Aug 29, 2018
    Posts:
    24
    Hi! Thx for the reply!

    I thought it would have been much more difficult.
    But strangely, adding the MainCamera at the end of the Timeline make the blend transition happen (the starting blend is working fine without adding the MainCamera at the begining of the Timeline).
    Yet, it is working. I must now add a quick fade in/out for the UI and I will be good!

    Many thanks @Gregoryl