Search Unity

Overriding Freecamera Cinemachine inputs or Freecamera axis inversion

Discussion in 'Cinemachine' started by sebsmax, Jul 24, 2017.

  1. sebsmax

    sebsmax

    Joined:
    Sep 8, 2015
    Posts:
    71
    It took me a while to figure it out, and it's fairly simple. So I'm posting that here to save newcomers a bit of time

    Hooking the controls to any external input system:
    Code (CSharp):
    1.      
    2.  
    3.         public void Start()
    4.         {
    5.             CinemachineCore.GetInputAxis = GetAxisCustom;
    6.         }
    7.  
    8.         public float GetAxisCustom(string axisName)
    9.         {
    10.             if(axisName == "Mouse X")
    11.             {
    12.                 return [YOUR INPUT VALUE HERE].x;
    13.             }
    14.             else if (axisName == "Mouse Y")
    15.             {
    16.                 return [YOUR INPUT VALUE HERE].y;
    17.             }
    18.  
    19.             return 0;
    20.         }
    Horizontal Axis inversion:

    Code (CSharp):
    1.      
    2.  
    3.         public void Start()
    4.         {
    5.             CinemachineCore.GetInputAxis = GetAxisCustom;
    6.         }
    7.  
    8.         public float GetAxisCustom(string axisName)
    9.         {
    10.             if(axisName == "Mouse X")
    11.             {
    12.                 return -UnityEngine.Input.GetAxis("Mouse X");
    13.             }
    14.             else
    15.                 return UnityEngine.Input.GetAxis(axisName);          
    16.         }
     
    Last edited: Jul 24, 2017
    rand_dev, piginhat, dommon and 5 others like this.
  2. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    83
    Awesome! Thanks :)
     
  3. rand_dev

    rand_dev

    Joined:
    Oct 24, 2017
    Posts:
    5
    Thanks a ton. Just in time when i was searching insanely for it.
    A suggestion: change the title to Freelook Cinemachine so that it can pop up more on search engine.
     
  4. youngmusa

    youngmusa

    Joined:
    Apr 15, 2018
    Posts:
    6
    Where do you put this code?
     
  5. abitofjohn

    abitofjohn

    Joined:
    Nov 6, 2012
    Posts:
    23
    Thanks! this was driving me crazy!
     
  6. MihajloNen

    MihajloNen

    Joined:
    Dec 7, 2015
    Posts:
    6
    Great. Thx a lot for the help!