Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Disable camera input during blending between two free look vcams?

Discussion in 'Cinemachine' started by JS101, Jul 6, 2018.

  1. JS101

    JS101

    Joined:
    Nov 15, 2012
    Posts:
    9
    I have a blend transition between two free look cameras. How could I go about disabling the user input between those transitions, so that the user cannot change the aim of those cameras until the blend has completed?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,714
    You would have to intercept Cinemachine's call to the input system, and check if there is a blend in progress.

    To get User input, Cinemachine calls the delegate CinemachineCore.GetInputAxis(), whose default implementation just calles Input.GetAxis(). You can hook in here, check CinemachineBrain.IsBlending, and just return 0 if it is.
     
  3. JS101

    JS101

    Joined:
    Nov 15, 2012
    Posts:
    9
    Thanks. Got it figured out with your help. Here's my code if it helps anyone else:

    Code (CSharp):
    1.  void Start () {
    2.         CinemachineCore.GetInputAxis = GetAxisCustom;
    3.         brain = Camera.main.GetComponent<CinemachineBrain>();
    4.     }
    5.  
    6.     private void Update()
    7.     {
    8.         if (brain.IsBlending)
    9.         {
    10.             isLocked = true;
    11.         }
    12.         else
    13.         {
    14.             isLocked = false;
    15.         }
    16.     }
    17.  
    18.     public float GetAxisCustom(string axisName)
    19.     {
    20.         if (axisName == "Mouse X")
    21.         {
    22.             if (!isLocked)
    23.                 return Input.GetAxis("Mouse X");
    24.             else
    25.                 return 0;
    26.         }
    27.         else if (axisName == "Mouse Y")
    28.         {
    29.             if (!isLocked)
    30.                 return Input.GetAxis("Mouse Y");
    31.             else
    32.                 return 0;
    33.         }
    34.         return UnityEngine.Input.GetAxis(axisName);
    35.     }
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,714
    Nice!
    You can make that even simpler and more versatile, like this:
    Code (CSharp):
    1.     private float GetAxisCustom(string axisName)
    2.     {
    3.         if (brain.IsBlending)
    4.             return 0;
    5.         return Input.GetAxis(axisName);
    6.     }
    and bonus! you don't need an Update method
     
  5. JS101

    JS101

    Joined:
    Nov 15, 2012
    Posts:
    9
    Awesome! Yea, I was trying to figure out a way to remove the Update method (had considered a flag on a timer that toggles when I initiate a blend).

    Thanks as always!
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,714
    One thought: this implementation might be overkill, depending on your needs. Here is a common use-case: suppose you have 2 FreeLooks with subtle differences that you blend between based on game events (e.g. a Normal FreeLook and a Sprinting FreeLook with different settings). You wouldn't want to cut out the input when blending between those. So in that case, you would want to enhance this code with WhitleList (or BlackList) functionality, depending on which cameras are blending (you can get that info from the brain too).
     
  7. JS101

    JS101

    Joined:
    Nov 15, 2012
    Posts:
    9
    Thanks again. Yes, I'll definitely have to modify it a bit further. Right now I only have two cameras (one for 3rd person, one for viewing inventory).

    My inventory is a world canvas, so that camera zooms in just next to the character head.

    The current setup works fine for now, but later I will add more cameras where I'll have to figure out how to keep the view the same (and of course whitelist so I don't lose control)

    I'll probably add a "left shoulder" camera (right now it's a right shoulder 3rd person view).

    Also perhaps a run and or attack mode camera.

    For what it's worth, I'm having a lot of fun with Cinemachine. Previously I was using an asset called uFPS but after trying for like a week to get it to work like I needed it to I began completely reworking my camera and character control systems -- I'm glad I did!