Overriding Freecamera Cinemachine inputs or Freecamera axis inversion

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:

        public void Start()
        {
            CinemachineCore.GetInputAxis = GetAxisCustom;
        }

        public float GetAxisCustom(string axisName)
        {
            if(axisName == "Mouse X")
            {
                return [YOUR INPUT VALUE HERE].x;
            }
            else if (axisName == "Mouse Y")
            {
                return [YOUR INPUT VALUE HERE].y;
            }

            return 0;
        }

Horizontal Axis inversion:

        public void Start()
        {
            CinemachineCore.GetInputAxis = GetAxisCustom;
        }

        public float GetAxisCustom(string axisName)
        {
            if(axisName == "Mouse X")
            {
                return -UnityEngine.Input.GetAxis("Mouse X");
            }
            else
                return UnityEngine.Input.GetAxis(axisName);          
        }
14 Likes

Awesome! Thanks :slight_smile:

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.

Where do you put this code?

Thanks! this was driving me crazy!

Great. Thx a lot for the help!

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

1 Like

You write this script and then you put it onto the object that holds the Freelook camera script for cinemachine.

1 Like

Thank you! This works with controller input systems (like InControl). Works with Free Camera and Virtual Camera too. I’m using it for POV controller input.

hey what should i do with this: [YOUR INPUT VALUE HERE]
i have no idea i try Mouse X/Mouse Y but it doesnt work

This thread is now quite old, and Cinemachine has built-in features to do many of the things that you would need this script for. What are you trying to accomplish?

this doesnt work. any update on getting CM working with mouse and gamepad?

Can you be more specific about what exactly you’re trying to do and why it doesn’t work for you?

what is the best solution to code both mouse and game pad input axis with bolt? i can only use bolt. i tried C# for 6 months. I use bolt only now.

i need to control input axis string name with bolt into cinemachine. or i want to use new input manager but it is too hard and i broke my whole game last time i tried it. can it work with bolt???

I’m still having trouble understanding what you’re trying to do. Why can’t you just set up your input channels in the inspector?

Thanks, Greg. As far as I can tell, I can only input one axis string name per free look axis. I would like TWO on each simultaneously. mouse and right analog stick.

As I understand, I am to leave the axis field BLANK which allows me to code as many as I want. What I’m having trouble finding is what code to use to do such an operation, (and then of course translate that to bolt, if indeed i can.)

The easiest way is to make a custom script that inherits AxisState.IInputAxisProvider (see Interface AxisState.IInputAxisProvider | Cinemachine | 2.6.17). Add that custom script to your vcam. The vcam will find it and ask the script whenever it needs an input value. Your script’s implementation of GetAxisValue() will query whatever input source you care about, and return the result.

Unfortunately I can’t help you with Bolt, I have never used it.

@Gregoryl
My apologies if I am bothering. Using InputAxisProvider to use cinemachine with the new input works wonderfully but, here’s is where I am stuck: when you add a touchscreen bind inside a Looks action (default input map when creating player input) this will aloud to control cinemachine on mobile when you touch the screen, but if you have a image / joystick with the on-stick script for the new input system also on mobile both input will cross; while moving the player with the joystick the camera also moves.

Do you have any tips in how to use both input without crossing each other?

1 Like

Maybe you can ask on the input forum: https://forum.unity.com/forums/input-system.103/
My guess is that you have to set up separate actions for player and camera control.

Both actions are separated. Will try on the input forum :wink: thanks.