using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public float m_MoveSpeed = 1f; public float m_CameraRotation; public float m_LookSensitive; public Transform m_Eye; public float m_LookSmooth; public float m_BodyRotation; // Start is called before the first frame update void Start() { Cursor.lockState = CursorLockMode.Locked; } void LookAround() { float mouseX = Input.GetAxis("Mouse X"); float mouseY = Input.GetAxis("Mouse Y"); //mouseX = -0.1f; // test jittery m_CameraRotation -= mouseY * Time.deltaTime * m_LookSensitive; m_CameraRotation = Mathf.Clamp(m_CameraRotation, -90, 90); Quaternion rot = Quaternion.Euler(m_CameraRotation, 0, 0); m_Eye.localRotation = Quaternion.Slerp(m_Eye.localRotation, rot, m_LookSmooth); m_BodyRotation += mouseX * Time.deltaTime * m_LookSensitive; rot = Quaternion.Euler(0, m_BodyRotation, 0); transform.localRotation = Quaternion.Slerp(transform.localRotation, rot, m_LookSmooth); } // Update is called once per frame void Update() { float moveX = Input.GetAxisRaw("Horizontal"); float moveZ = Input.GetAxisRaw("Vertical"); Vector3 dir = transform.right * moveX + transform.forward * moveZ; if (dir.magnitude > 0) { dir = dir.normalized; Vector3 velocity = dir * m_MoveSpeed; transform.position += velocity * Time.deltaTime; } LookAround(); } }