using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 5f; // Скорость движения
public float mouseSensitivity = 2f; // Чувствительность мыши
public Transform cameraTransform;
private float xRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
transform.Rotate(0f, mouseX, 0f);
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f); // не переворачиваемся
cameraTransform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
// ДВИЖЕНИЕ КЛАВИШАМИ
// W/S — вперёд/назад, A/D — влево/вправо
float moveZ = Input.GetAxis("Vertical"); // W = +1, S = -1
float moveX = Input.GetAxis("Horizontal"); // D = +1, A = -1
Vector3 movement = new Vector3(moveX, 0f, moveZ);
movement = transform.TransformDirection(movement);
transform.Translate(movement * speed * Time.deltaTime, Space.World);
}
}