Perekyp/Assets/Scripts/Player/Movement/PlayerLook.cs

33 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
public class PlayerLook : MonoBehaviour
{
[Header("Look Settings")]
[SerializeField] private float mouseSensitivity = 150f;
[SerializeField] private Transform playerBody;
private float xRotation = 0f;
private void Start()
{
// Блокируем курсор в центре экрана и скрываем его
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
public void ProcessLook(Vector2 input)
{
float mouseX = input.x * mouseSensitivity * Time.deltaTime;
float mouseY = input.y * mouseSensitivity * Time.deltaTime;
// Расчет наклона камеры с ограничением, чтобы нельзя было сломать шею
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// Применяем вращение камеры (вверх/вниз)
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// Вращаем само тело игрока (влево/вправо)
playerBody.Rotate(Vector3.up * mouseX);
}
}