#I cant get camera left and right movement to work

1 messages · Page 1 of 1 (latest)

zinc badger
#
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
{
    public float mouseSensitivity = 100f;

    public Transform playerBody;

    float xRotation = 0f;
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    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);
    }
}```
pine rune
#

Make sure that the script is attached to the camera, that the playerBody field actually contains a reference to the player body, and that the camera is a child of that body.

#

You also do not need to multiply mouse axis with Time.deltaTime; their values already are framerate-independent.

pine rune
#

You have not assigned your player body field.