using UnityEngine; using UnityEngine.InputSystem; public class PlayerMove : MonoBehaviour { [Range(0f, 10f)] public float moveSpeed = 5f; [SerializeField] private InputManager _inputManager; [SerializeField] private GameObject _camera; private CharacterController _controller; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { _controller = GetComponent(); } // Update is called once per frame void Update() { Vector3 input = new Vector3(_inputManager.moveInput.x, 0f , _inputManager.moveInput.y); Vector3 moveDir = Vector3.zero; moveDir += MoveDir(input); moveDir += Gravity(); _controller.Move(moveSpeed * moveDir * Time.deltaTime); } Vector3 MoveDir(Vector3 input) { Quaternion camRotation = Quaternion.Euler(0f, _camera.transform.rotation.eulerAngles.y, 0f); input = camRotation * input; return input; } Vector3 Gravity() { return Physics.gravity; } }