Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Cinemachine FreeLook camera and New Input System?

Discussion in 'Input System' started by MlleBun, Nov 7, 2019.

  1. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    Hello,
    Are those two compatible or will they be in future release? For now, I'm using Old input system for Input Axis Name parameter in the CM Free Look cam and the new system in my character controller. But I was wondering if CM will support the new input system later or vice-versa.
    Thanks.
     
  2. Gandarufu

    Gandarufu

    Joined:
    Nov 10, 2014
    Posts:
    13
    This worked for me:
     
  3. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    I bet you did :confused: I'm having headaches too. Many thanks for your help, I'm going to test it tonight!
     
  4. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    Hello @Gandarufu, again thanks for the help. Just to let you and others know some points.

    1. As Cinemachine still needs the old input system, don't forget to check if you have "Mouse X" and "Mouse Y" inputs in the Input list ; or if you choose to have custom names (in my case it's "CamControlX" and "CamControlY"), don't forget to create them in the old Input Manager list as you'll get errors. I'm hoping that won't be mandatory later.

    System.ArgumentException: Input Axis CamControlX is not setup.
    To change the input settings use: Edit -> Settings -> Input a
    t (wrapper managed-to-native) UnityEngine.Input.GetAxis(string)

    2. Also, I modified a little bit your code, LookDelta not being updated when moving my gamepad rightstick.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class InputCameraController : MonoBehaviour
    5. {
    6.     private PrototypeInputSystem inputSystem;
    7.     private Vector2 LookCamera; // your LookDelta
    8.     public float deadZoneX = 0.2f;
    9.  
    10.     private void Awake()
    11.     {
    12.         inputSystem = new PrototypeInputSystem();
    13.  
    14.         inputSystem.PlayerGameplay.CameraControl.performed += ctx => LookCamera = ctx.ReadValue<Vector2>().normalized;
    15.         inputSystem.PlayerGameplay.CameraControl.performed += ctx => GetInput();
    16.     }
    17.  
    18.     private void GetInput()
    19.     {
    20.         CinemachineCore.GetInputAxis = GetAxisCustom;
    21.     }
    22.  
    23.     public float GetAxisCustom(string axisName)
    24.     {
    25.         // LookCamera.Normalize();
    26.  
    27.         if (axisName == "CamControlX")
    28.         {
    29.           if (LookCamera.x > deadZoneX || LookCamera.x < -deadZoneX) // To stabilise Cam and prevent it from rotating when LookCamera.x value is between deadZoneX and - deadZoneX
    30.            {
    31.              return LookCamera.x;
    32.            }
    33.         }
    34.  
    35.         else if (axisName == "CamControlY")
    36.         {
    37.             return LookCamera.y;
    38.         }
    39.  
    40.         return 0;
    41.     }
    42.  
    43.     private void OnEnable()
    44.     {
    45.         inputSystem.PlayerGameplay.Enable();
    46.     }
    47.  
    48.     private void OnDisable()
    49.     {
    50.         inputSystem.PlayerGameplay.Disable();
    51.     }
    52. }
    53.  
    And it's working beautifully!
     
    Last edited: Mar 9, 2020
  5. northman

    northman

    Joined:
    Feb 28, 2008
    Posts:
    131

    Hi @MlleBun , Today I just learned new Input System and Cinemachine. I try to make the Action in Editor dialog, but I got issue when it ran.
    Please help me to check my setup and figerout the problem.

    Best regards,
     
  6. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    Hi @northman, are you having errors or is the script working but you are not having the desired behaviour on your mouse control?
     
  7. Worstharbor

    Worstharbor

    Joined:
    Jan 29, 2020
    Posts:
    3
    Ok so I did the thing all I'm trying to do is set up the mouse to be used by CM

    It's not exactly moving but there are no errors in the code. I'm not sure if I should add it as a component to the camera? Should I use Unity Engine.Inputcontroller? I am at a stalemate.

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4.  
    5. public class FreeLookUserInput : MonoBehaviour
    6. {
    7.     private PlayerControls playerControls;
    8.     private Vector2 lookCamera;
    9.     public float deadZoneX = 0.2f;
    10.     // Start is called before the first frame update
    11.     private void Awake()
    12.     {
    13.         playerControls = new PlayerControls();
    14.  
    15.         playerControls.Player.Look.performed += ctx => lookCamera = ctx.ReadValue<Vector2>().normalized;
    16.         playerControls.Player.Look.performed += ctx => GetInput();
    17.     }
    18.  
    19.     private void GetInput()
    20.     {
    21.         CinemachineCore.GetInputAxis = GetAxisCustom;
    22.     }
    23.  
    24.     public float GetAxisCustom(string axisName)
    25.     {
    26.         //LookCamer.Normalized
    27.         if(axisName == "Mouse X")
    28.         {
    29.             if(lookCamera.x > deadZoneX || lookCamera.x < -deadZoneX)
    30.             {
    31.                 return lookCamera.x;
    32.             }
    33.         }
    34.         else if (axisName == "Mouse Y")
    35.         {
    36.             return lookCamera.y;
    37.         }
    38.         return 0;
    39.     }
    40.     private void OnEnable()
    41.     {
    42.         playerControls.Player.Enable();
    43.     }
    44.     private void OnDisable()
    45.     {
    46.         playerControls.Player.Disable();
    47.     }
    48. }
     

    Attached Files:

  8. nettamenteBoss

    nettamenteBoss

    Joined:
    Jun 16, 2013
    Posts:
    1
    Hi,
    I've managed the problem in this way:


    Code (CSharp):
    1. public class SwitchCamera : MonoBehaviour
    2. {
    3.  
    4.     public GameObject cinemachine;
    5.  
    6.     private CinemachineFreeLook freeLook;
    7.  
    8.     void Start()
    9.     {
    10.         freeLook = cinemachine.GetComponent<CinemachineFreeLook>();
    11.  
    12.  
    13.     }
    14.  
    15.     public void Look(InputAction.CallbackContext context)
    16.     {
    17.  
    18.  
    19.         freeLook.m_XAxis.m_InputAxisValue = context.ReadValue<Vector2>().x;
    20.         freeLook.m_YAxis.m_InputAxisValue = context.ReadValue<Vector2>().y;
    21.  
    22.     }
    23.  
    24.  
    25. }
    - Assigned my cinemachine FreeLook Camera to "cinemachine" in the Editor .

    - Left blank the fields "Input Axis Name" both in Axis Control > Y Axis and Axis Control> X Axis

    - Assigned the SwitchCamera.Look function to Events> Player > Look (Callback Context) in the Player Input Component, according to https://docs.unity3d.com/Packages/c...ting-input-indirectly-through-an-input-action
     
  9. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    723
    @Gregoryl Any authoritative advice on this? And are there any plans to free Cinemachine from the clutches of the old input system?
     
    MlleBun likes this.
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,961
    @transat We are working on better support for the New Input System
     
  11. Beshop_

    Beshop_

    Joined:
    Feb 5, 2020
    Posts:
    1
    Hello, I'm working on my project and I have this problem, but I tried this solution and it's fine, I haven't error but now when I move my mouse, the freelook cam turn but don't stop, even when I release my mouse. Someone has met this problem ?
     
  12. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    Hi
    Hi @Beshop_ , could you post a screenshot of your Input actions to see your setup? Thanks ;)
     
  13. JadeTheurgist

    JadeTheurgist

    Joined:
    Apr 11, 2015
    Posts:
    1
    Hey @Beshop_ , I think I was having the same problem you were, where the camera would continue rotating in a direction even after you stopped giving input. I managed to find a solution. Along side where the inputs are assigned in the code's Awake function add this:

    Code (CSharp):
    1. playerControls.Player.Look.canceled += ctx => LookCamera = Vector2.zero;
    This makes it so when you stop giving input, the LookCamera Vector2 will reset its value and stop moving rather than retain the last value it had and keep moving the camera.

    Hope this helps!
     
  14. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    109
    Hi everyone, got the same issue with the mouse, but I could solve it just by changing the binding with no change in the script shared above :

    upload_2020-5-30_11-6-36.png

    Hope it solves your problem!
     
  15. smontambault64

    smontambault64

    Joined:
    Sep 7, 2018
    Posts:
    1
    Asprewga and Savdog like this.
  16. dorusoftware

    dorusoftware

    Joined:
    Jul 5, 2012
    Posts:
    67
    trying to follow a tutorial on youtube about creating a third person controller, two hours later I'm trying to find a fix for cinemachine and input package. unity learning workflow never let me down.
     
  17. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    723
    Agree re the Unity learning workflow. But FYI, Cinemachine 2.6 now has a component you can attach to your virtual cameras to fix the issue. If you spend another hour on the Unity blog and forum you will find info about it. Good luck!

    On a less cynical note, documentation aside, the Cinemachine team is actually one of the best at Unity. They do quality work and are quite responsive on the forum so no doubt you will get the answers you are looking for.
     
  18. dorusoftware

    dorusoftware

    Joined:
    Jul 5, 2012
    Posts:
    67
    What about helping a fellow forum member and just tell me how to do this instead
     
  19. transat

    transat

    Joined:
    May 5, 2018
    Posts:
    723
    From memory you add a component called input axis provider (or something like that) to your virtual camera. I'm not in front of my project right now so can't be more specific.
     
unityunity