Search Unity

Virtual camera blend issue

Discussion in 'Cinemachine' started by Bastienre4, Aug 2, 2017.

  1. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    52
    Hello there !

    We decided to use Cinemachine as our camera solution and we are facing a weird blend behaviour.



    As you can see, when enabling the second virtual camera, instead of blending the camera target smoothly, it keep looking at the first target at the beginning of the blend and then switch to the second target.

    Two questions :
    - Its this the desired blend behaviour ?
    - Can we change this somehow ?

    Thanks for your answer and have a nice day ! :)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    In fact this is the intended behaviour. When you blend between vcams with different LookAt targets, the LookAt point during the blend is not a linear lerp between the target points (which is what you are looking for, I believe). Instead, it is a spherical linear interpolation that is more robust under more circumstances.

    There are 2 ways to change this.
    1. Remove the LookAt target from one or both of your vcams. This will force CM to simply slerp the camera rotations, giving you the effect you want in this case, or
    2. Change the way CM interpolates the LookAt target. Go to CameraState.cs, around line 170 or so, and make this mod:
      Code (CSharp):
      1.                 #if false
      2.                 state.ReferenceLookAt = state.CorrectedPosition + Vector3.Slerp(
      3.                         stateA.ReferenceLookAt - state.CorrectedPosition,
      4.                         stateB.ReferenceLookAt - state.CorrectedPosition, adjustedT);
      5.                 #else
      6.                 state.ReferenceLookAt = Vector3.Lerp(
      7.                         stateA.ReferenceLookAt, stateB.ReferenceLookAt, adjustedT);
      8.                 #endif
      Warning: this is a global mod, and will affect all CM cameras. Use at your own risk
     
    Bastienre4 likes this.
  3. Bastienre4

    Bastienre4

    Joined:
    Jul 8, 2014
    Posts:
    52
    Hey, thanks for your quick answer !

    As we want to keep the LookAt target, I'll go for the second proposition ! :)

    Have a nice day !
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Please let me know how that works out for you, and whether the mod creates other blending weirdnesses. There is some controversy here about what is the best blending strategy for the LookAt target, and we might have to make this choice more explicit in future releases. Thanks.
     
  5. ElectricMonk

    ElectricMonk

    Joined:
    Sep 3, 2014
    Posts:
    5
    Hi Gregory,

    Thanks for sharing that trick. I know this is an old thread, but It would be great if this were exposed as an option in the future. I found it helped smooth out some camera weirdness related to blending from a view looking out to one side back to a follow cam behind a moving object. I can send you more details if you're interested. Thanks! We're really enjoying the new tools!

    Dylan
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    CM 2.1 (available in beta) has the modified version as standard. Consensus seems to be that it's better that way.
     
  7. d-grandry

    d-grandry

    Joined:
    Jun 14, 2017
    Posts:
    4
    Hi,

    I did encounter some weird blend that occur when the start and the end point have opposite forward. This blend is between a Virtual Camera as a tracked dolly (not auto) and a cinemachine external camera

    (Preview : https://imgur.com/YiesujH )

    Also, I tested it with the v2.1 RC and it's still happening.

    Have a nice day !
     
  8. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    416
    I can't really tell what's happening here since you didn't show Hierarchy/Inspector windows.
    Could you upload this/make repo project and send it to @Gregoryl / @Adam_Myhill, It would really help.
    Thanks.
     
  9. d-grandry

    d-grandry

    Joined:
    Jun 14, 2017
    Posts:
    4
    Ok, unfortunately I can't make a repo because we have an internal git but I've made a showcase (unity project). I will send it by PM to @Gregoryl.

    Thanks !
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    @d-grandry Hi Dorian,

    The problems is due to Cinemachine attempting to negotiate a difficult blend (one that involves a travelling Lerp right through the object being looked at) without sufficient information to do it properly.

    The CinemachineExternalCamera, while useful in some situations, is lacking a key piece of essential information: the LookAt target. The blender needs to know what the camera is looking at, otherwise it's stuck doing what is essentially a Slerp, which can give inferior results in circumstances such as these.

    I would suggest, instead of using CinemachineExternalCamera, that you add a CinemachineVirtualCamera to the Player Orbital camera. Sets its aim and body to Hard Constraint, and - importantly - set its lookAt target to the point that the Player Orbital camera is looking at. Then the blends will be nice.

    Let me know if that works for you.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    @d-grandry Hi again,

    Another (perhaps better) option is to just add the LookAt field to the CinemachineExternalCamera, to provide the missing information. I've done that here, and it seems to do the trick in your scene.
     

    Attached Files:

  12. d-grandry

    d-grandry

    Joined:
    Jun 14, 2017
    Posts:
    4
    Hi,

    So I did try both solutions and they both work. But I have a question does the lookAt in cinemachineExternalCamera will be added in a further version ? (To know if we have to re-apply this when updating cinemachine later on)

    Thanks !
     
    Last edited: Sep 27, 2017
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,845
    Yes it's a good addition and it's going into the next beta
     
  14. d-grandry

    d-grandry

    Joined:
    Jun 14, 2017
    Posts:
    4
    Ok, thanks ! Have a nice day.