Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug How do I make my camera rotation in sync with my player rotation?

Discussion in 'Editor & General Support' started by danthegreat78, Nov 21, 2023.

  1. danthegreat78

    danthegreat78

    Joined:
    Aug 27, 2023
    Posts:
    9
    I have recently created a cinemachine camera and I would like to get my player rotating with the camera kind of like when you have a bow and arrow in some games. Here is my camera script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class camera controller : MonoBehaviour
    6. {
    7.     private float x;
    8.     private float y;
    9.     public float sensitivity = -1f;
    10.     private Vector3 rotate;
    11.     private void Start()
    12.     {
    13.         Cursor.lockState = CursorLockMode.Locked;
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         y = Input.GetAxis("Mouse X");
    19.         x = Input.GetAxis("Mouse Y");
    20.         rotate = new Vector3(0, y * sensitivity, 0);
    21.         transform.eulerAngles = transform.eulerAngles - rotate;
    22.     }
    23.  
    24. }
    The player is moving and I can turn the player with my mouse. The problem is that the camera only automatically goes to the back of the player slowly while the player is moving. Here is an example:



    Is there any way to fix this?
     
    Last edited: Nov 21, 2023