- Home /
Question by
SilkiesRBest · Dec 19, 2021 at 01:01 PM ·
axislookrotation
why hasthis has locked my X axis looking
hi im following a tutorial made by brackeys and im trying to make a working first person view so that you can look around and it has stopped allowing me to look in the x axis at all and instead i can look up and down in the y axis.
here is the code.
using System.Collections; 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;
}
// 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);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613050736im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Quaternion.LookRotation only on Y axis 0 Answers
How can I rotate towards/look at a specific axis of a collided object? 2 Answers
Rotating a 2D sprite to face a target on a single axis. 3 Answers
Quaternion LookRotation/Slerp Axis Lock 3 Answers
How does LookRotation work in relation to ray cast? 1 Answer