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

Using 2 cameras at same time

Discussion in 'Cinemachine' started by CyberInteractiveLLC, Oct 21, 2018.

  1. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    hi,
    I'm testing cinemachine, and there 1 issue I have is at some points while moving my character I want to switch between cameras (which have different properties) I do this by changing priority number... however, when I switch back... the camera that was switched off starts at the position it was switched off at and slowly returns behind my object... so my question how to switch between cameras while having both cameras stay in same positions that they should ?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Your vcams are of the "simple follow" variety, right?

    In that case, they follow the player in their own way when active, and stay put when inactive. What you need to do is position the incoming vcam at the same point as the outgoing one, then activate it (activate its game object, don't just change the priority number). So: position the deactivated vcam, then activate it and deactivate the outgoing vcam at the same time.
     
  3. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    Not sure if those are different things but I'm using Transposer + Lock to target settings with the Virtual Camera. while moving player object during behavior change I simply want different damping values, so I switch between virtual cameras however when I switch back the newly switched on camera is not at the position it should be right away, it moves from the position it was switched off to the position it should be.

    How would I position the offline virtual camera ?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    If it's lock to target then it's super easy: just disable then enable the incoming vcam. It will snap to the right place upon enable.
     
  5. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    keep priority # even ?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes. If multiple vcams share the highest priority, the most-recently-enabled one will dominate.
     
  7. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    still same issue, perhaps i shall take a clip of it ?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    That would be helpful :) Also if you could post images of the vcam inspectors, for both vcams. And your project hierarchy, showing the vcams and the target.
     
  9. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    the other vcam has the same excat settings except for Z Damping which 0.2, i simply set the gameobject off and on when the player speeds up or when slow down. in hierarchy the player is at top then cameras
     
  10. CyberInteractiveLLC

    CyberInteractiveLLC

    Joined:
    May 23, 2017
    Posts:
    306
    Created a new project just to be sure, same issue... it's annoying
    here the video:
    https://sendvid.com/zybzvp7l

    this is the script, I'm just changing speed on W input and switch cameras, camera settings are excat same as above just one with Z Damping 0.2 (c_1) and other 1 Z Damping (c_2)
    i think the problem has to do with switching cameras while a camera is still returning to normal position.

    Code (CSharp):
    1.     float speed;
    2.     public float norSpeed = 20;
    3.     public float fastSpeed = 50;
    4.     public GameObject c_1;
    5.     public GameObject c_2;
    6.     private void FixedUpdate()
    7.     {
    8.         if (Input.GetKey(KeyCode.W))
    9.         {
    10.             c_1.SetActive(false);
    11.             c_2.SetActive(true);
    12.  
    13.             speed = fastSpeed;
    14.         }
    15.         else
    16.         {
    17.             c_1.SetActive(true);
    18.             c_2.SetActive(false);
    19.  
    20.             speed = norSpeed;
    21.         }
    22.      
    23.  
    24.         transform.position += transform.forward * speed  *Time.deltaTime;
    25.     }
    Edit: heres another video, this time i use 6 Z Damping for it to be clear, at first blends the 2 positions normally, but if i switch during blend time the camera goes way back

    https://sendvid.com/whjp1lcr

    Edit 2: Seems like a way to fix this is to add a tiny blend time like 0.3 or 0.4, however, its still happening but more rare ... is there any other way ?

    Edit 3: OK, i've added a blend check when switching between vcams and it seems to have fixed it fully !
    Code (CSharp):
    1. if (Brain.IsBlending)
    2.     return;
     
    Last edited: Oct 26, 2018
    Gregoryl likes this.