Search Unity

I can only look up and down not left and right

Discussion in 'Getting Started' started by stefant561, Dec 5, 2020.

  1. stefant561

    stefant561

    Joined:
    Dec 5, 2020
    Posts:
    1
    I followed a yt tutorial trying to make simple fps movement and I cant figure out why I cant look left or right only up and down.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class Look : MonoBehaviour
    {
    public float mouseSpeed = 100f;
    public Transform playerBody;
    float xRotation = 0f;

    void Start()
    {
    Cursor.lockState = CursorLockMode.Locked;
    }
    void Update()
    {
    float mouseX = Input.GetAxis("Mouse X") * mouseSpeed * Time.deltaTime;
    float mouseY = Input.GetAxis("Mouse Y") * mouseSpeed * Time.deltaTime;


    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);

    transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    playerBody.Rotate(Vector3.up * mouseX);
    }
    }