Rotating Cinemachine Virtual Camera via mouse click and drag input

Hello everyone, I am currently working on trying to create a rotating camera with the new Input system with mouse drag that also tracks the player. I am not sure where to start and cannot find many resources using Cinemachine + new Input system + click and drag mouse input.

Things I’ve tried:
CinemachineVirtualCamera with the body set to Framing Transposer (for following the player) and the aim as POV. I have found that changing the values on the vertical and horizontal axis on the POV are the values I want to change, but am not sure how to set up the Input Asset. I have added a CinemachineInputProvider that is supposed to map the input axes.

I have also added some code to attempt to map the mouse position on click and drag to the vertical and horizontal axes on the virtual camera.

Hopefully someone can point me in the right direction :slight_smile:

public void OnRightClickDrag(InputAction.CallbackContext context)
    {
        beganDrag = true;
        if (context.started)
        {
            playerController.initialPoint = Mouse.current.position.ReadValue();
        }
        if (context.canceled)
        {
            beganDrag = false;
        }
    }
private void RotateCamera()
    {
        currentPoint = Mouse.current.position.ReadValue();
        Vector2 pointDiff = initialPoint - currentPoint;
        if (playerInput.beganDrag)
        {
            if (pointDiff.x < 0)
            {
               cinemachinePOV.m_HorizontalAxis.Value += 0.5f;
            }
            else if (pointDiff.x > 0)
            {
                cinemachinePOV.m_HorizontalAxis.Value -= 0.5f;
            }
            if (pointDiff.y < 0)
            {
                cinemachinePOV.m_VerticalAxis.Value += 0.05f;
            }
            else if (pointDiff.y > 0)
            {
                cinemachinePOV.m_VerticalAxis.Value -= 0.05f;
            }
        }
    }

If I’m understanding you correctly, you want a 3rd person camera that orbits around the player. I have a camera like this that I’m happy with. The way I did it was much simpler. Assign a Follow Target (not Look At) to your Framing Transposer. Get rid of any other stuff on the Virtual Camera. Set the Camera Distance. Aim parameter should be “Nothing”.

At that point you should be able to manually change the rotation values in the inspector and it should frame the target no matter where the camera is. So then at that point, in your code, just alter the virtualCameraObject.transform.localEulerAngles to rotate the camera around the target. Then just tweak the Framing Transposer parameters until you’ve got a feel you like.

I have a PlayerCameraControl component that has a Vec3 cameraTargetRotation field, and I use the stick/mouse to delta the X and Y values of this. So when the stick is .1 in X, we add .1 * cameraSpeed * Time.deltaTime to cameraTargetRotation.x. Same with Y. Then clamp the values if you want.

As far as the Input System side goes, I have an Input Action called LookAction, and then when I want to read it, I just say lookAction.ReadValue() and use that.

So overall, it’s quite simple but works great because Cinemachine is magic.

2 Likes