Search Unity

Question Smooth transition from one VCam to another when the player is at the edge of two colliders

Discussion in 'Cinemachine' started by MlleBun, Jul 20, 2020.

  1. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi everyone,

    How would you solve this problem ?
    I have two colliders A & B. When the player is in A, I activate VCam1 and when in B, I activate VCam2. Both colliders represents two successive zones where the player can go back and forth.

    The transitions work ; I got from Vcam1 to VCam2 and vice-versa when the player triggers the individual zones, but when I'm just in between those zones, the transitions glitches (hysteresis issue).
    upload_2020-7-20_14-7-2.png
    I tried to increase both colliders so that they intersects into each other and also tried to match the edges so that they touch perfectly, but still, it takes a few millimeters to cause the glitch. When in the middle, the both VCam1 and VCam2 are activated and toggle between each other.

    Thanks for any ideas how to solve this !
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Set up the colliders so that they have a little overlap. On each collider, add a CinemachineTriggerAction script.

    Set up the CinemachineTriggerAction so that when the player enters, the associated vcam is activated, and when the player exits, the associated vcam is deactivated. Put the 2 vcams at the same priority. You don't need to write any custom code for this.

    This will work (there will be no hysteresis) because when 2 active vcams have the same priority, Cinemachine prioritizes the most-recently-activated one.
     
    edhumali likes this.
  3. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Thanks for your reply @Gregoryl !

    I removed my Activate/Deactivate script and tried the CinemachineTriggerAction and put both priorities at the highest (15). At the start of the game, both Vcams (1 and 2) are activated. I don't know if it's normal. Thus even before entering the zone, I'm on Vcam2 camera view. Should I deactivate both cameras at Start ?

    When entering Zone1, as both vcams are of the same priority, it choses the Vcam2 instead of Vcam1. Removing 1 to the priority of Vcam2 solved the issue.

    And I still have the glitch unfortunately. I have a pretty large intersection to test the fix and when I'm right at the edge of Zone1, without moving the player, they deactivate/activate alone, thus causing the cameras glitch and cut from one to another.

    Trigger Zone 1
    upload_2020-7-20_20-37-12.png

    Trigger Zone 2
    upload_2020-7-20_20-37-32.png

    upload_2020-7-20_20-47-0.png

    upload_2020-7-20_20-57-16.png

    VCam_Transition_Glitch.gif
     
    Last edited: Jul 20, 2020
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Start with both cameras deactivated, and put them at the same priority. What happens then?
    Also: why do you have -2 in Skip First? Put 0.
     
  5. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi, sorry for the late answer. Skip First is actually set automatically. I have about 6 different VCams in the scene and sometimes this parameter is automatically on 0, sometimes -2 and other times -6.

    I did as said, that is all vcams that has to be activated on triggerEnter are deactivated at start and the priorities are the same. But still, being inbetween two zones makes the camera alternate between previous and current cameras. It's only spotted when the transition is in Cut and not Ease In/Out.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I've tried to reproduce your issue, but I cannot get it to happen as you describe. For me it works perfectly. Maybe it's something about the way you set up your scene. I've attached my scene here, for comparison. Import it into your project, play the TriggerZoneTest scene, and use WASD to move the player through the trigger zones.
     

    Attached Files:

    MlleBun likes this.
  7. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Many thanks @Gregoryl for your time spent on this bug. In fact in the project, there is no bug but when changing the Vcam's parameters like my project, the glitch comes back. I follow the player and I have a Framing Transposer as Body. With relief, I do not have the back and forth movement in your project, but I still have this weird "pop" when the camera cuts to the next transition and it's even more evident when you have an Ease In/Out transition.

    Here is when I have the cut transition
    https://drive.google.com/file/d/1VvBnU-S8mzJdTAx1w4DDef1dhd0eUEw5/view?usp=sharing


    Here are the parameters on all vcams - I set both vcam1 and vcam 2 to a camera distance of 10 in the Body.
    upload_2020-8-8_9-27-57.png

    upload_2020-8-8_9-28-18.png


    Also, I noticed something strange in the gui on the first transition, might me not related but the FOV field changes to Orthographic Size? https://drive.google.com/file/d/1qYRmsRdfeJAcKEoR09iGtI6jc1CIOrdQ/view?usp=sharing
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I think the pop is because you are following the player with damping, and then cutting to a new camera, but the new camera only wakes up when it is activated, so there is no damping on it initially.

    To fix this, enable the "Inherit Position" checkboxes of the vcams. That way, when they are activated they will initially assume the same position as the outgoing camera.

    upload_2020-8-10_12-17-2.png

    And yes, if you have an orthographic main camera, then the FOV in the vcam will change to Orthographic Size.
     
  9. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Weird, my camera is not orthographic and the FOV text reappears when I quit Play mode. Might be a bug?

    I'll do this, but I'm not sure it will fix it. I think I did that before and still got those glitches. Have you tried it in your project?
    For now, I'm playing with priorities instead of activating/deactivating the vcams and surprisingly, it works way better. The workflow is as followed :
    • All cameras are of priority 0 unless being in a trigger zone.
    • onTriggerEnter, I set the last cam's priority to 0 and the current to 20.
     
  10. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Hi everyone, since 2020 versions, it seems that my issues aren't there anymore ! Let me debug more and keep you posted ;)