Search Unity

Disabling State Driven VCam Child During Specific Blend

Discussion in 'Cinemachine' started by praveensharma, May 2, 2019.

  1. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    Hi!

    Cinemachine is awesome!

    I'm attempting to blend between two camera states. The main camera state is a Free Look camera which is a Zelda / Mario style third person camera. The second is a camera which locks on behind the player character when the player character "locks on" to an enemy (like in Zelda).

    This works great and the blends look good when the player character is not moving. When I am transitioning from the lock on camera to the free look camera AND the character is moving, the lock on camera is still following the character so it causes the blend to the free look camera to be jarring. I am using "Blend Hints" so the free look position during this blend is correct.

    I've tried different blend types and really what I'd like to do is just have the lock on camera stay static when its blending into the free look camera so that the blend is a smooth transition back to free look when the character is moving.

    I looked at Gregory's post here and then realized this isn't possible with state driven cameras:

    https://forum.unity.com/threads/dis...-blending-between-two-free-look-vcams.539244/

    Is there a good way to do something similar in a state driven camera for this situation? I can't find an API for checking CamA vs. CamB during a state driven camera transition as in the example above.
     
    Last edited: May 2, 2019
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    When you say that you'd like the lock-on camera to remain static, do you mean that you don't want it to move at all, or that you don't want it to respond to mouse/joystick input?

    Can you show the inspectors of the FreeLook and the LockOn?
     
  3. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    Thanks Gregory!

    Let me explain a bit better:

    Since the "Lock On" camera sits behind the player and directly tracks their movement, when the player stops "locking on" and they move to the right or left, the "Lock On" camera quickly swings behind the player making the blend to the "Free Look" camera pretty rough.

    I was thinking that by preventing joystick input to the Lock On camera during that blend, I could prevent this from happening and have a smooth blend from the last "acceptable" position of the Lock On Camera.

    Images attached.
     

    Attached Files:

  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    What version of CM are you using? It's possible that you're tripping over a bug in the blending.
     
  5. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    2.3.3 with 2019.1
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Try upgrading to 2.3.4, available in preview on the staging repository. Let me know if that fixes it.
     
  7. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    Thanks Gregory.

    Apologies - I'm a bit of a Unity noob here. Can you link me to instructions on how to setup the staging repository? I've found a few things online but they don't seem to be relevant for 2019.

    I have "Show Preview Packages" selected in the package manager. I also attempted to update the manifest.json.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    With a text editor edit your project's Packages/manifest.json file and add this line:
    "registry": "https://staging-packages.unity.com",
    immediately before the "dependencies" line. Then open Package Manager, and you will see the experimental and unpublished content in addition to full-fledged releases. Use at your own risk.
     
  9. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    I upgraded but still have the same issue. I don't think this is a bug - just a side effect of my unfamiliarity with how to properly handle Cinemachine state blends.

    You can see the issue here: https://www.dropbox.com/s/vr11m2lgq88efny/CinemachineExample.mov?dl=0

    What you see is the Player Character locking on and off of the capsule. The blend here is smooth because there is no movement. Then you see how the orbital lock on works - when the user continues to hold the right or left keys while letting go of the lock on button, the behind the back camera swings to be behind the player (as it should) however this is during the blend to the free look camera so it creates an unseemly transition.

    I'm trying to deactivate joystick input for the lock on camera during this transition to have a smoother blend.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Thanks for the video. I understand the problem better now.

    I'm not convinced that turning off the joystick input will fix the issue, however. Please correct me if I'm wrong, but it seems that the lock-on is tracking your target with an ordinary Transposer - the joystick is not affecting that camera, only the player position/orientation. So, moving the player will move that camera, whether it's done with the joystick or not.

    Maybe what you have to do is to temporarily turn off tracking on that vcam during the blend away from it. You can do this by disabling the transposer component of the vcam: vcam.GetCinemachineComponent<CinemachineTransposer>().enabled = false.

    The next question is how to disable it only during the blend out. The vcam is blending out if it is Live but not the current active vcam. So brain.ActiveVirtualCamera != lockOn && CinemachineCore.Instance.IsLive(lockOn) == true. You can poll that condition in a script.
     
  11. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    Thanks for this. Will try it out. I'm using a state driven camera for this blend though and don't think the brain can see the active virtual camera. I will look into how to check the active virtual camera via state camera.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Right. You'll have to ask the SDC for it's current live camera: use sdc.LiveChild.
     
  13. praveensharma

    praveensharma

    Joined:
    Oct 4, 2017
    Posts:
    7
    So I tried this solution and it almost worked. There was still a hard cut due to the offset in the transposer (the transposer gets removed so the offset is removed). Also - I wasn't sure how to properly re-enable the transposer reliably. This may be a bug but when I was playing in engine and had the "Lock On" camera active in the inspector, the Transposer would get removed and then throw a bunch of "Object is Null" errors when I attempted to enable it. Happy to look into this further if you would like to investigate this.

    Turns out after all this I think all I needed to do was adjust the dampening parameters in the "Lock On" camera's transposer. With just a bit of dampening on the transposer, the camera has enough time for a nice blend without the sudden jump in character orientation.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    That's a happy outcome :D