I have been trying to implement a roblox-like camera control system in unity but with the CinemachineFreeLook's built in InputProvider script that's connected to my input system actions, the camera moves whenever I just move my mouse and doesn't require right mouse button to be held.
What I want to happen is that whenever I hold right click, the mouse locks in place and moving the mouse when right click is held orbits the camera around the player. I have set up the orbits in the FreeLook camera.
With the cinemachine input provider, there's an option to enable auto inputs. With it enabled, cinemachines script takes priority and controls camera movement whenever I perform an action connected to the input provider. I have connected a look action to the input provider script that looks like this: Input System
So the first thing I tried was disabling AutoEnableInputs so that I could edit the camera movement with my own script but since it relies on the Axis values updating from the InputProvider script, it doesn't work, as those axis values update from the inputs in the InputProvider (which I disabled). The only thing I think would work is either approaching this completely different, or maybe I could get some help with my CameraController script:
public class CameraController : MonoBehaviour
{
/* [SerializeField] */
/* private float orbitSpeed = 2f; */
private CinemachineInputProvider inputProvider;
public PlayerInputActions playerControls;
private InputAction deltaAction;
private InputAction dragAction;
private Vector2 deltaInput = Vector2.zero;
private bool isDragging = false;
private void Awake()
{
playerControls = new PlayerInputActions();
inputProvider = GetComponent<CinemachineInputProvider>();
deltaAction = playerControls.Player.Look;
dragAction = playerControls.Player.Drag;
}
private void OnEnable()
{
deltaAction.Enable();
dragAction.Enable();
dragAction.performed += OnDrag;
dragAction.canceled += OnDrag;
deltaAction.performed += OnDelta;
}
private void OnDisable()
{
deltaAction.Disable();
dragAction.Disable();
}
private void OnDrag(InputAction.CallbackContext context)
{
isDragging = !isDragging;
}
private void OnDelta(InputAction.CallbackContext context)
{
deltaInput = context.ReadValue<Vector2>();
}
// Update is called once per frame
void Update()
{
float x = inputProvider.GetAxisValue(0);
float y = inputProvider.GetAxisValue(1);
float z = inputProvider.GetAxisValue(2);
if ((x != 0 || y != 0) && isDragging)
{
OrbitPlayer(x, y);
}
}
/* public Vector2 OrbitDirection(float x, float y)
{
Vector2 direction = Vector2.zero;
return direction;
} */
public void OrbitPlayer(float x, float y)
{
Debug.Log("Orbiting");
}
}
OrbitPlayer() is never getting called as the floats x,y,z are never changing from the value 0 as I have disabled the inputs from the input provider as of now, I want this to work with the input provider somehow though.
I have tried looking everywhere for some answers but usually it was either using the old input manager or wasn't applicible in my context. Thanks for reading :)