Search Unity

Question How to make third person cinemachine camera rotate up/down with vertical mouse position

Discussion in 'Cinemachine' started by christimbol, Aug 31, 2022.

  1. christimbol

    christimbol

    Joined:
    Nov 28, 2019
    Posts:
    12
    Hello I am working on a third person game and I can't figure out how to make the third person camera from cinemachine angle with the mouse Y position from the new input system .
    How do i change my camera euler angle ?
    Code (CSharp):
    1.     private void TurnWithMouse()
    2.     {
    3.         xRotation -= mousePosition.y;
    4.         xRotation = Mathf.Clamp(xRotation, -30f, 50f);
    5.         Vector3 targetRotation = head.transform.eulerAngles;
    6.         targetRotation.x = xRotation;
    7.         head.eulerAngles = targetRotation;
    8.         playerCamera.eulerAngles = targetRotation;
    9.   /*       Debug.Log(playerCamera.eulerAngles);*/
    10.         transform.Rotate(Vector3.up, mousePosition.x * Time.deltaTime * mouseSensitivityX);
    11.     }
    upload_2022-8-31_14-15-0.png
    upload_2022-8-31_14-15-13.png
     
    Last edited: Aug 31, 2022
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Hi
    Could you show us your virtual camera?
    The solution depends on what kind of vcam/setup you have.

    In general, your vcam's position and rotation is controlled by the Body and Aim components of that vcam.
     
  3. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Your vcam is using 3rdPersonFollow that means that you need to rotate your Follow target. In your case the gameObject is called LookAt.

    Instead of applying your rotation logic to the vcam, apply it to its Follow target.

    Note: If LookAt is part of your robot that you do not want to modify, then create an empty gameObject attached to the robot and Follow this instead.
     
    Atilli likes this.
  4. christimbol

    christimbol

    Joined:
    Nov 28, 2019
    Posts:
    12
    Thank you sir!!
     
    gaborkb likes this.