Search Unity

Issue of camera flipping/rotating during a blend

Discussion in 'Cinemachine' started by Pelican_7, Dec 4, 2018.

  1. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Hi all,

    I'm having an issue when blending between two cameras whereby my camera flips around to point in the opposite direction as it transitions over long distances. For example, in the video linked below, the first blend transition works well (short distance). In the second transition (medium distance), you can see the camera begin to rotate at the transition's midpoint. In the third transition (long distance), you can see the camera rotate backwards at the transition's midpoint.

    https://drive.google.com/open?id=1qS6-Hp4lcR5iG-Q_a_iWggfbxfGvmOSp

    My question is how can I prevent the camera from rotating like this during a blend so that all the transitions look like the first one?

    Some of my settings that may be relevant (?!):
    - I am using a Free Look Camera, transitioning into a Virtual Camera.
    - Both cameras have a Blend Hint of Spherical Position.
    - The Free Look camera has both a Follow transform and a Look At transform (which doesn't move during the transition).
    - The Free Look camera has its Heading Definition set to Target Forward.
    - The Free Look camera has all Aim rigs set to Hard Look At with no Look At Override.
    - The Virtual camera has a Look At target transform but no Follow transform.
    - The Virtual camera has its Aim set to Composer.

    What I have tried:
    - Adjusting the Blend Hint of both cameras (Spherical Position/Cylindrical Position). Whilst changing this setting does affect the transition somewhat, it still has the issue described above.
    - Using a Custom Blend asset on the Brain but this only appears to control the easing.

    Any advice is much appreciated, thanks!
    -andy.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's always tricky to get a good blend when the LookAt target changes. Try setting the blend hint to this:

    upload_2018-12-4_17-31-17.png

    Also: what version of Cinemachine are you using?
     
    JonnyG7 likes this.
  3. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Thanks for the response @Gregoryl.

    I get the same issue with the Screen Space Aim Blend Hint I'm afraid (I set it on both the Free Look cam and Virtual cam). I'm using Cinemachine v2.2.7 installed via the Package Manager in Unity 2018.3.0b12.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    hmmm... this is puzzling. I'd like to try to repro this and see what's going on. Can you please post here:
    • the world positions of the 4 targets: initial, close, medium, and far
    • Inspectors for the FreeLook and the vcam, showing all relevant settings
    I will try to recreate this scenario with simple objects.
    Thanks
     
  5. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Ok great, thanks a lot @Gregoryl!

    Here are all the settings, let me know if you need anything else.

    Free Look Camera (Initial)
    Position: X: 0 Y: 170 Z: -130
    Rotation: X: 0 Y: 0 Z: 0

    Free Look Camera Settings

    FL1.PNG
    FL2.PNG

    The Follow and Look At transform of the Free Look Camera is a game object positioned at:

    Follow and Look At Transform
    Position: X: 0 Y: 40 Z: 0
    Rotation: X: 0 Y: 0 Z: 0

    The three Virtual Cameras that are transitioned to all have identical camera settings with one exception - their Look At transform. So I have included the position of each Virtual Camera's Look At transform too.

    Near Virtual Camera
    Position: X: 0 Y: 30 Z: -60
    Rotation: X: 30 Y: 0 Z: 0
    Look At Transform Position: X: 0 Y: 0 Z: 0

    Mid Virtual Camera
    Position: X: -150 Y: 30 Z: 140
    Rotation: X: 30 Y: 0 Z: 0
    Look At Transform Position: X: -150 Y: 0 Z: 200

    Far Virtual Camera
    Position: X: -300 Y: 30 Z: 340
    Rotation: X: 30 Y: 0 Z: 0
    Look At Transform Position: X: -300 Y: 0 Z: 400

    Virtual Camera Settings
    VC1.PNG

    -andy.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks for that.

    I get the best results with Blend hint = None on the vcams, and blend hint = ScreenScreenSpaceAimWhenTrargetsDiffer on the FreeLook, and no InheritPosition on anything.

    What's happening is that the camera positions and lookAt targets are being lerped independently, and because of the layout of things, one passes by the other, causing the camera to swing.

    The only way, at present, to make that effect go away is to remove the LookAt target from the vcams, and just hardwire the vcam rotations, the same as you did for the positions. Without a LookAt target, the vcam will have no lookAt position to lerp, so it will have no choice but to slerp the rotations, which is what you're looking for, I think.
     
  7. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Ahh thanks a lot - removing the vcams LookAt target resolves the issue!

    I was using the Composer with a LookAt on the vcams so I could dynamically position the focal point in the left side of the screen with any aspect ratio (Screen X: 0.25), but without this I can still just about get away with having a fixed vcam lookAt rotation.

    Thanks so much for your help @Gregoryl – much appreciated!
     
  8. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
  9. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    @aesi_aes Could you send us a repro project? You can send a direct message to me or submit an official bug report (> How to report bugs <).
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's a little unclear from the video, but if all the vcams have Framing Transposer in the Body and Do Nothing in the aim, then the problem is likely to be in the Transform component. Cinemachine is not modifying the vcam rotations, it's just blending between them. Try setting all the rotations of the vcams to the same thing.
     
    gaborkb likes this.
  11. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    "Try setting all the rotations of the vcams to the same thing."

    But that is actually what I want to achieve... blending between these two cameras with different angles.

    I already have a "solution" where I only have one VirtualCam: here I do transition to different rotations in my own script (VirtualCamController).

    But now I want to set Confiners in some rooms... when I set a new confiner, the VirtualCam just snaps to that confiner...

    So my newest idea was to go back to "blending between two cameras with different angles" where some of these cameras have a confiner already set up. My hope was to blend smoothly between these.

    Your comment tells me that won't work, as there will always be some kind of angular tilting / flipping involved?

    Next idea: I now have a DynamicConfiner script, which sets the confiner to player position on enable, and then smoothly transitions to the actual Confiner position... let's see where we get with that...
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Maybe you need to explain again what you are trying to make, and what is going wrong. It's hard for me to tell from the video. You have many cameras, I don't know where they are placed, or what triggers the blends, or what they are supposed to look like.

    Let's leave the confiner aside for the moment, and try to get the unconfined cameras to blend correctly. In the absence of a LookAt target, the blending algorithm just slerps the angles. That will take the shortest angular path. You should never get spins of more than 180 degrees, or pops. You have both in the video. We need to understand why that is happening.

    Can you describe to me the camera behaviour you are trying to get?

    Even better, as @gaborkb suggested, can you make a toy project that reproduces the spinning issue? If you can post that, it will be much faster to narrow this down.
     
    Last edited: May 18, 2021
  13. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
  14. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thank you for the upload. Using it I was able to confirm that you are tripping over a bug in Cinemachine that was fixed last week. The fix will be shipped with the next CM release. If you don't want to wait for it and if you feel comfortable embedding and modifying package code, I can send you a patch.
     
    ferverence likes this.
  16. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Woah, that would be nice if you could send me a patch...

    But actually it's not that urgent... if you say the next release is let's say next week, that would be enough for me :)
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    It's not next week.
     
  18. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Then of course, it would be great if you could send me that patch :D

    Thanks!
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    First, you have to embed Cinemachine into your project so that it becomes writable. Do this by moving the "com.unity.cinemachine" folder from the package cache to your project's "Packages" folder. Make sure it's called "com.unity.cinemachine" in the destination (i.e. without the version identifier).

    Then, find CameraState.cs in there and replace it with the attached file. Let me know if it works for you.
     

    Attached Files:

    Last edited: May 19, 2021
  20. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Hm I moved the "com.unity.cinemachine" from the Package Cache to the Assets/Packages, renamed it (version number), and removed the reference from both manifest.json and packages-lock.json... but when I start the editor now, the editor shows a "Hold on (busy for x:xx)" indicator with message "EditorApplication.update", and Unity UI doesn't react anymore (apart from the indicator bar "updating the time").

    Didn't find anything on that topic in the webz...

    But as I said, it's not that urgent.. :)
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    What do you mean, "renamed it (version number)"? What is the new name? It should be "com.unity.cinemachine".
    Close Unity, remove the cinemachine lines from manifest.json and packages-lock.json, and restart Unity.
     
  22. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    That's what I did...

    - moved the com.unity.cinemachine@2.7.3 to Packages,
    - renamed it to com.unity.cinemachine
    - removed it from manifest.json and packages-lock.json
    - started Unity...

    Now it freezes, or shows the "Hold on (busy for x:xx) --> EditorApplication.update"
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I just tried this with your test project:
    I moved the cinemachine folder from package cache (in Library) to Packages/com.unity.cinemachine
    Then I opened Unity. Didn't touch manifest.json or packages-lock.
    It worked fine.
     
  24. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Aaaaaand you were right! Now it works...

    I have a Packages folder in my Assets folder, too, and by accident placed the cinemachine package there... of course it has to be Unity's package folder in the root directory...

    Stupid me, sorry for that!!

    And your fix also works like a charm... everything fine now!

    Thanks for your help!
     
    Gregoryl likes this.
  25. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    51
    Hi @Gregoryl -
    I had a similar problem where my LookAt lerp was causing a cross over with the follow lerp, as you described, making the camera spin a bit on one of my transitions.

    Your code change did prevent the spin, but caused the camera to pitch forward (upside down) briefly during the transition. I also noticed it had a side effect on some other transitions where it caused the camera to roll, though there was no roll in either source vcams.

    While digging in I noticed there is code for another blend hint - IgnoreLookAtTarget. I had to modify the script to make it usable, but it actually works well for this particular blend. Do you know of any reason it's not exposed or that I shouldn't use it?

    Thanks.
     

    Attached Files:

  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    @FuriousEX Can you send me a scene that shows the spurious roll and pitch? This sounds like a problem.

    For the IgnoreLookAt target blend hint, there is a less hacky way to make use of it: just attach this extension to the vcam:
    Code (CSharp):
    1. using Cinemachine;
    2.  
    3. public class CinemachineIgnoreLookAtExtension : CinemachineExtension
    4. {
    5.     /// <summary>Standard CinemachineExtension callback</summary>
    6.     protected override void PostPipelineStageCallback(
    7.         CinemachineVirtualCameraBase vcam,
    8.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    9.     {
    10.         if (stage == CinemachineCore.Stage.Finalize)
    11.             state.BlendHint |= CameraState.BlendHintValue.IgnoreLookAtTarget;
    12.     }
    13. }
    14.  
     
  27. FuriousEX

    FuriousEX

    Joined:
    Mar 13, 2014
    Posts:
    51
    Thanks - sorry can't make you a repro scene at this time - just thought you might like to know what I observed.
     
  28. ferverence

    ferverence

    Joined:
    Jul 15, 2014
    Posts:
    56
    Still had the issue in CM2.8.0 / U2019.4.8f1 on vcams with differing targets which jittered and looked in the wrong directions. Screen Space Aim didn't work either. I compromised for now and am just using cylindrical blend hint which works but isn't exactly what I would like.
     
  29. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If you'd like to send me a simple project that repros the issue I can take a look.
     
  30. ferverence

    ferverence

    Joined:
    Jul 15, 2014
    Posts:
    56
    Thanks @Gregoryl

    I changed Body and Aim within the VC's to 'Do nothing' and that fixed it. So it was an issue with the values within Transposer and Composer on them (Which were default). It's clear I can change values now to stop the flipping/rotations, even though 'Do nothing' is working quite well for what I need.
     
  31. carlosmar4979

    carlosmar4979

    Joined:
    Apr 22, 2022
    Posts:
    1
    This worked for me, else if you set Body and Aim to "Do nothing" might as well not even have the camera.
     

    Attached Files:

  32. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Hello there,

    I am checking with every new Cinemachine update, if your fix has been added @Gregoryl
    But it still behaves like described above, in Cinemachine 2.9.5 ... the camera does a strange flip when it comes to 90°...

    Any chances that this will be fixed in the 'Release' version?

    Here is a video of the current 2.9.5 Cinemachine version:

    https://drive.google.com/file/d/1Fg2TfbO3JRdLxD6Ec33fb7_sGN3ZADkt/view?usp=share_link

    And here is the expected output, how your fix (2.9.0-pre6) works:

    https://drive.google.com/file/d/1rkTa8RIlqgc-SKhjHUTvMnyuPrE-4pnK/view?usp=share_link

    Thanks in advance :)
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I doubt that your issue is the same as the one in this thread. It might be a good idea to start a new thread. If you do, please include an image of the inspector for your vcam.

    EDIT: sorry, just read farther back in the thread again and I see now what you're referring to. Will check your old upload, but first please confirm that it is still relevant and that you haven't changed the approach.
     
    Last edited: Mar 13, 2023
  34. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Still the same than on my old posts - I didn't change anything on my camera system... (one of the few systems I barely need to touch ;) because except for this little bug, Cinemachine works like a charm and is smooth AF :D )

    I am pretty sure in this case, because I check for the issue everytime... since the Package Manager always updates to the newest package when I update the Unity version, and I have to go back to 2.9.0-pre6 :)
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Unfortunately I no longer have your original test project, and the links above are dead. Would you be willing to shoot me another small repro project?
     
  36. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
  37. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks for the upload. I see the issue. It's caused by the blend trying to keep the target framing but using WorldUp and therefore tripping over gimbal lock at 90 degrees. You can fix this by attaching the custom IgnoreLookAtTarget extension to the camera that is past 90 degrees.

    Find the custom extension here.
     
  38. aesi_aes

    aesi_aes

    Joined:
    Dec 16, 2013
    Posts:
    17
    Works like a charm... thank you :)

    BTW: +1 for your video on Cinemachine 3!
    Keep up the great work :)
     
    Gregoryl likes this.