Search Unity

Moving Freelook camera with an Xbox (or any) controller

Discussion in 'Cinemachine' started by mrCharli3, Mar 11, 2019.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    How can I change so that I can move the camera around with the right stick of a controller, as well as the current (default) mouse bindings?
     
    Last edited: Mar 12, 2019
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,149
    Just change the Input Axis Name to be the one you want, from the Input system.

    upload_2019-3-13_11-11-27.png
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    Right, I saw that, so I added these 2 in my Input (now have 2 Mouse X and 2 Mouse Y Inputs):



    From my understanding, that should be enough? but must be missing something.

    EDIT:
    Even if I change the Input axis name to "asdasddas", which is not a Valid input Axis, the input for moving freelook with my mouse still works. So that seems strange?
     
    Last edited: Mar 13, 2019
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,149
    Can you try with different names, ones that are not duplicated?
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    I have, whatever I put inside "Input Axis Name", the mouse works, but the controller does not.

    I changed the names to "Joy X", and "Joy Y", and replaced the Input in the pictures above with those names. does not work.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    2,149
    Well that's just screwy. Are you saying the FreeLook is ignoring the input axis name you give it in its axis? Mouse X/Y is not hardcoded anywhere. Are you changing it in the right FreeLook? Do you have some other script that overriding it? To eliminate interference from elsewhere, can you reproduce the problem in a new, empty project?
     
  7. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    99% sure everything is default. Ill try in a new project to make sure.
     
  8. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    Ok so,

    To move the camera with the mouse, I need to hold down Mouse(1).
    If I hold it down, while moving my joystick, it catually works.

    So this is the issue. It only accepts the input when I hold down mouse(1), how can I fix this? I want that to be the behaviour for when I use my mouse, but obv wont work with a controller.
     
  9. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    336
    This last issue was just me being stupid, been so long since I made a script for the mouse input that I just thot it was default Cinemachine.

    I've attached this script to my main cam:

    Code (CSharp):
    1. public class FreeLookUserInput : MonoBehaviour {
    2.  
    3.     private bool _freeLookActive;
    4.  
    5.     // Use this for initialization
    6.     private void Start()
    7.     {
    8.         CinemachineCore.GetInputAxis = GetInputAxis;
    9.     }
    10.  
    11.     private void Update()
    12.     {
    13.         _freeLookActive = Input.GetMouseButton(1); // 0 = left mouse btn or 1 = right
    14.     }
    15.  
    16.     private float GetInputAxis(string axisName)
    17.     {
    18.         return !_freeLookActive ? 0 : Input.GetAxis(axisName == "Mouse Y" ? "Mouse Y" : "Mouse X");
    19.     }
    20. }
    Any clever ideas on how I can limit this to when I use a mouse? Since I need the Axis name for mouse and gamepad input to be the same.