Answer the question
In order to leave comments, you need to log in
Why does the camera move 90* on the x-axis when the scene starts?
Implementing a simple 1st person camera control system. When the scene starts, the camera abruptly drops 90 degrees in X. The same code works fine in the tutorial I copied it from:
using UnityEngine;
public class MouseLook : MonoBehaviour
{
//скорость вращения
public float mouseSens = 100f;
// игрок
public Transform playerBody;
// угол вращения по X
float xRotation = 0f;
void Start()
{
// фиксирую курсор в центре
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
// получаю ввод с мышки
float mouseX = Input.GetAxis("Mouse X") * mouseSens * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSens * Time.deltaTime;
xRotation -= mouseY;
// проблема происходит из-за этой строчки кода которая должна ограничивать вращения по оси X
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question