For some odd reason whenever I press the ‘play’ button to test my scene, the player camera moves a little to the right while the player body stays in the same position. When I rotate my character, everything moves as you would expect only the camera stays off centre.
I narrowed it down to the script for the camera causing the issue only I don’t know how. I was hoping that maybe someone could help? Here is my code for the player camera:
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 120f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis(“Mouse X”) * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis(“Mouse Y”) * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
I am relatively new to Unity so if I’m missing something really obvious, then that is why.
Thanks!