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

Question Unnatural continuous cinemachine camera switching

Discussion in 'Cinemachine' started by Jang_Hyun, Sep 20, 2022.

  1. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    Here is my situation.

    vCam1 is looking at the map from some high position. (Look At = None or Ground)
    vCam2 is looking at the Player from the same position (Look At = Player)
    vCam3 is looking at the Player behind the Player. (Look At = Player)

    And I want to change camera view : vCam1 -> vCam2 -> vCam3 If I click "change" button.
    But Switching Camera view is not natural. (
    )

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Cinemachine;
    5.  
    6. public class PrioritySetting : MonoBehaviour
    7. {
    8.     public CinemachineVirtualCamera vCam1, vCam2, vCam3;
    9.  
    10.     public float time = 2.0f;
    11.  
    12.     public void GoToVCam3()
    13.     {
    14.         vCam3.Priority = 12;
    15.     }
    16.  
    17.     public void SwitchCamera()
    18.     {
    19.         vCam2.Priority = 11;
    20.         Invoke("GoToVCam3", time);
    21.     }
    22.  
    23.     public void RollBack()
    24.     {
    25.         vCam1.Priority = 10;
    26.         vCam2.Priority = 9;
    27.         vCam3.Priority = 9;
    28.     }
    29. }
    30.  

    I want to move the camera naturally while looking at the player at the same time.
    It feels like this ↓

    -------------------- Time Line ------------------>
    vCam1 -> vCam2 -> vCam3 (X)

    vCam1 -> vCam2
    vCam2 -> vCam3 at the same time.


    Also I want to turn the camera exactly the opposite path If I click "rollback" button.
    vCam3 -> vCam2
    vCam2 -> vCam1 at the same time.

    I don't want to use Dolly Track because the player can be anywhere.

    It would be great if you help me on this problem.
    Thank you.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    If both cameras have the same LookAt target, the camera will continue to look at it during a blend. If the targets differ, then the LookAt point will blend from one position to the other. If one of the cameras has no LookAt target, then only a slerp is possible from one rotation to the other, and that rarely gives natural results.

    So, to get maximal control, you should set LookAt targets to all your cameras. Also, you can control how the LookAt point blends using this setting on the cameras:

    upload_2022-9-20_11-25-10.png

    For the overlapped blending, have you tried using a timeline? Put a Cinemachine track on a timeline, create ovlerlapping clips for the 3 camera in a linear fashion. The length of the overlap controls the blend time. Then you can just play the timeline whenever you want.
     
    Jang_Hyun likes this.
  3. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    Thank you for your answer.
    But I wanted to create an object on runtime, and my camera have to see object, so I gave the example above.
    Therefore, if I press the rollback button, I want to cinemacine's Look At = Ground.

    Also, Can I create a timeline and a cinema machine on runtime?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You can create the timeline asset in advance, and bind to the objects at runtime.

    Another possible solution is to use CinemachineMixingCamera. That gives you precise control of a continuous blend of up to 8 cameras. You would have to drive their weights manually, perhaps using animation curves.
     
    Jang_Hyun likes this.
  5. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    Thank you. I would try mixing camera! have a good day :D
     
    Gregoryl likes this.
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You can also try BlendListCamera. That might be even better, and simpler.
     
    Jang_Hyun likes this.
  7. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    I already tried it with blend list camera, but it was unnatural (such as my video)
    Can the blend list run the cinemachine at the same time?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I don't understand the question.
     
    Jang_Hyun likes this.
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    BlendList camera will give you this when it is enabled:
    -------------------- Time Line ------------------>
    vCam1 -> vCam2 -> vCam3 (X)

    vcam1 should have the ScreenSpaceAim blend hint.
    vcam 2 and 3 should have CylidricalPosition blend hint.
     
    Jang_Hyun likes this.
  10. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    I tried it!, But it still is unnatural, because vCam1 -> vCam2 move and stop for a short time.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    What happens if you get rid of vcam2, and just blend straight from vcam1 to vcam3? Keep the blend hints.
     
    Jang_Hyun likes this.
  12. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    Thank you!, It helps me a lot.
    I solve my problem.
    Again, Thank you for your help!!
     
    Gregoryl likes this.
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    So now you don't need the BlendList camera, you can just do normal blends.
     
  14. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    I understand,
    I just change priority of vCam1 now, right?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes.

    FYI it is also possible to set all the vcams to the same priority, then do vcam.MoveToTopOfPrioritySubqueue() for the vcam that you want to activate. It might not be appropriate for your setup, but it is there if you need it.
     
  16. Jang_Hyun

    Jang_Hyun

    Joined:
    May 1, 2019
    Posts:
    14
    Thank you for your tips, I love cinemachine.
    Have a good day!
     
    Gregoryl likes this.