So in my game I currently have a third person camera + movement script and I’m now creating a first person camera looking script using Brackeys first person movement tutorial but I can only look in the x direction while brackeys can look all around him and my code seems the same as his.
I use code that activates or deactivates the first and third person scripts according to wich camera I’m currently on but that works perfectly.
I don’t get any errors when in game.
Brackeys video:
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FirstPersonMouse : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Vector3 offset;
public Transform playerBody;
private float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void LateUpdate()
{
transform.position = playerBody.position + offset;
transform.rotation = playerBody.rotation;
}
// 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);