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 Camera Blending Issue

Discussion in 'Cinemachine' started by AmirAzmi, Jan 22, 2021.

  1. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    Hey guys, I have been having this issue with the blending between the Freelook Camera and a Virtual Camera. When I set the priority of the Virtual Camera to be higher than the Freelook Camera, the blending between the Freelook Camera going to Virtual Camera overshoots relative to the angle I am looking away from the object I am trying to look at.


    I have attached all the information I believe to be necessary in the zip. If you need information please let me know.

    Things I have tested: Testing the different permutations of the inherit and blending settings. Messing with different Camera blends using a camera blend asset. I have also looked into checking where and how I change my priority for the cameras.

    I am using Unity 2019.4 and Cinemachine 2.7.1
     

    Attached Files:

  2. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8


    A small gif of what is happening.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You're having problems, I think, with the nature of the blend interpolation. Nothing in the BlendAssets will affect that. The problem likely is an artifact of the specific placement in worldspace of the targets and cameras, and the fact that you're changing LookAt targets form one camera to the other. The BlendHints will have the most impact over how the blend is done.

    It's difficult from the images you sent to get a clear picture of what's going on. Can you put together a small project that reproduces this setup and send me that?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Hang on... why do you have the camera in the target group? That feels weird and wrong. What exactly are you trying to do with the target group?

    upload_2021-1-22_16-27-12.png
     
  5. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    Hey Gregory, thanks for the response, I got a small sample scene in place. Please load the sample scene provided in Assets/Scenes/SampleScene.unity. The keys to move are WASD, and G to "Target" the small cubes that are tagged as targetable.
     

    Attached Files:

  6. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    Right, so the reason the camera is in the target group is because I am trying to solve the issue of the camera pushing forward through objects to look at a target when there is something in between the follow and the target.
     
  7. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    I have tested without the camera from the target group and that does fix the blending, but the resultant behavior is that when there is an object between the follow object and the target, the camera is pushed infront of the object in between.
     
  8. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    This is what the resultant behavior looks like. I didn't know the blending would be effected by the camera being in the target group. That is very interesting.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks for uploading the scene, it makes it easier to understand.

    The problem you describe is due to the CinemachineCollider on CMTargeting camera. Its job is to keep the LookAt target visible by pulling the camera in front of any occluding objects. That's what its doing - it doesn't care about the Follow target. If you remove the CinemachineCollider then the camera no longer pops in front of objects.

    What I think you need is to make CinemachineCollider consider the FollowTarget instead of the LookAt target. Unfortunately, Cinemachine doesn't come with this option out of the box.

    Fortunately, it's very easy to make a custom CM extension. Here is one that forces the collider to consider the Follow target instead of the LookAt target. Drop it into your project and add it to your CMTargeting vcam via the Extensions dropdown in the inspector.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that uses the Follow target as look at
    6. /// </summary>
    7. [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
    8. public class LookAtFollow : CinemachineExtension
    9. {
    10.     [Tooltip("Where in the Cinemachine Pipeline to apply this change")]
    11.     public CinemachineCore.Stage ApplyAfter;
    12.  
    13.     private void Reset()
    14.     {
    15.         ApplyAfter = CinemachineCore.Stage.Aim;
    16.     }
    17.  
    18.     protected override void PostPipelineStageCallback(
    19.         CinemachineVirtualCameraBase vcam,
    20.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    21.     {
    22.         if (stage == ApplyAfter)
    23.         {
    24.             var follow = vcam.Follow;
    25.             if (follow != null)
    26.                 state.ReferenceLookAt = follow.position;
    27.         }
    28.     }
    29. }
    30.  
     
  10. AmirAzmi

    AmirAzmi

    Joined:
    Sep 4, 2019
    Posts:
    8
    Thank you Gregory for the help!
     
    Gregoryl likes this.
  11. mitulmahish

    mitulmahish

    Joined:
    Feb 2, 2021
    Posts:
    1
    you may see the unity tutorial