Change in-game mouse look pivot

In my 3rd person game, I’m using this to rotate the plaxer and look around:

    public void Rotate()
    {
        float horizontalRotation = Input.GetAxis("Mouse X");
        float verticalRotation = Input.GetAxis("Mouse Y");

        transform.Rotate(0, horizontalRotation * mouseSensitivity, 0);
        cameraHolder.Rotate(verticalRotation * mouseSensitivity, 0, 0);

        Vector3 currentRotation = cameraHolder.localEulerAngles;
        if (currentRotation.x > 180) currentRotation.x -= 360;
        currentRotation.x = Mathf.Clamp(currentRotation.x, upLimit, downLimit);
        cameraHolder.localRotation = Quaternion.Euler(currentRotation);
    }

Now when looking up and down, the camera still pivots on its own center without moving up and down.

I’d actually prefer the camera pivot to be the player’s head, effectively having the head in the center of the frame all the time wit hthe camera moving closer to the ground when looking up and moving higher up when looking down.

…how do I do that?

One approach is to insert an extra transform at the desired pivot point.

For instance in the case of your head, when you look down, the pivot point isn’t right between your eyes, but rather somewhere near the top of your neck, roughly.

With one extra GameObject in the hierarchy above the camera, offset from the camera a bit, you can pivot that one instead.

1 Like

Yep, that did it! Thank you!!

Just for completeness’ sake, I did have to set that GameObject as the cameraHolder in the script.

1 Like