Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

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:
    76
    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:
    26
    Thanks! this was driving me crazy!
     
  6. MihajloNen

    MihajloNen

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

    Hellzbellz123

    Joined:
    May 15, 2019
    Posts:
    12
    sorry to bump but this also works for Cinemachine and unitys new input system.
    take the delta from the mouse and then split the vector2 into .x and .y and then just return it
     
  8. kitchen54

    kitchen54

    Joined:
    Nov 7, 2013
    Posts:
    4
    You write this script and then you put it onto the object that holds the Freelook camera script for cinemachine.