Hello!
I am perfecting my own mouseLook script, and right now I am finishing up a tutorial that is helping me learn about controlling the camera with the mouse. Please help me understand why my mouseLook isn’t working like Brackey’s!
- I rotate the player’s game object on the Y axis.
- I rotate the gameObject (to my understanding…) on the X axis, which is seemingly working good…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myMouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
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);
}
}
my rotation side to side isn’t working. Can anyone help me out? Thank you!