Ive written code for a first person view, but for some reason my camera will not move left and right. I’ve written the code for it but whenever i move my mouse in the two directions, my screen gets choppy and doesn’t move… I shall leave my script here as well, may someone check it for me?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterLook : 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);
}
}
,I have written my code, but for some reason i can’t look left or right in first person view. I could a second ago but now when i try to turn, my screen gets choppy and won’t move.
I was following Brackeys tutorial on first person view and i can’t seem to figure out what’s wrong. Please help, i shall leave my code here as well.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharacterLook : 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);
}
}