Cinemachine freelook mouse down

I’m having a heck of a job trying to get the cmfreelook to only update the camera view when the left mouse button is down rather than the default whereby regardless the camera moves whenever the mouse if moved.

Is there a way to say to cinemachine only allow camera movement if user is moving mouse whilst holding the button down?

1 Like

Thank you! I had tried searching but obviously asked in the wrong way! I was actually rather close to this way!

so I am having a heck of a time trying to figure out exactly how to adapt the linked script to the new input system with the free look. I would like to have an on right mouse button down for the keyboard map but use the right joystick without a button press. I have messed around with modifiers but haven’t had any luck. Any suggestions?

Cinemachine has introduced an interface to better support the new input system and other custom input systems. Have a look at CinemachineInputProvider.

https://docs.unity3d.com/Packages/com.unity.cinemachine@2.6/manual/CinemachineAlternativeInput.html

So this is what I did put in place but I still can’t seem to make the look rotation dependent on a condition. I would like to allow the player to toggle on or off the look rotation. I haven’t found anything other than scripts for composites that are well beyond my skills. Any suggestions where to start?

You can make a custom version of CinemachineInputProvider that conditionally returns 0 for rotations if they are locked. Copy CinemachineInputProvider.cs, rename it to something else, then modify its GetAxisValue() method to check your locked setting and return 0 if rotation for that axis is locked. Use that new custom version as your input provider.

I know this is a little late, but here’s my first-pass solution to the above problem. I suspect that it fails with controllers where you don’t want a button press to allow camera control, but I have not tested that fully yet.

using UnityEngine;
using UnityEngine.InputSystem;
using Cinemachine;

/// <summary>
/// Extended Unity provided Cinemachine Input Provider, to add ability to have mouse down for look.
/// </summary>
public class CinemachineInputProviderEx : CinemachineInputProvider
{
    /// <summary>Button action for looking</summary>
    [Tooltip("Button action for Look Button")]
    [SerializeField]
    private InputActionReference LookButton;

    /// <summary>
    /// Implementation of AxisState.IInputAxisProvider.GetAxisValue().
    /// Axis index ranges from 0...2 for X, Y, and Z.
    /// Reads the action associated with the axis.
    /// </summary>
    /// <param name="axis"></param>
    /// <returns>The current axis value</returns>
    public override float GetAxisValue(int axis)
    {
        if (enabled)
        {
            //    If Action is set, then check that button is pressed, else ignore it.
            if (LookButton != null && LookButton.action != null)
            {
                if (LookButton.action.ReadValue<float>() == 0.0f)
                    return 0f;
            }

            return base.GetAxisValue(axis);
        }

        return 0;
    }
}
1 Like