using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; [RequireComponent(typeof(UnityEngine.InputSystem.PlayerInput), typeof(CharacterController))] public class PlayerInputController : MonoBehaviour { [SerializeField] private float m_playerSpeed = 1; [SerializeField] private float m_rotationSpeed = 1; [SerializeField] [Tooltip("Used to spin on spot\n" + "0 = back\n" + "0.5 = left/right\n" + "1.0 = forward")] private AnimationCurve m_turnRadius; private UnityEngine.InputSystem.PlayerInput m_input; private CharacterController m_controller; private Vector3 m_desiredDirection; private bool m_recievedInput => m_desiredDirection.magnitude != 0; private YeetController m_yeetController; public GameObject testChild; public GameObject body; private void Awake() { m_input = GetComponent(); m_controller = GetComponent(); m_yeetController = GetComponent(); } private void Update() { ApplyRotation(); ApplyMovement(); LockAxis(Vector3.up); } private void OnMovement(InputValue value) { Vector2 m_recievedInput = value.Get(); m_desiredDirection = new Vector3(m_recievedInput.x, 0.0f, m_recievedInput.y); } private void OnYeet() { m_yeetController.parent = body; switch (m_yeetController.yeetState) { case YeetController.YeetState.Unheld: m_yeetController.Hold(testChild); // Grab nearest baby break; case YeetController.YeetState.Held: m_yeetController.Yeet(); // Yeet baby break; case YeetController.YeetState.Yeeting: // Cooldown? break; } } private void ApplyRotation() { transform.forward = Vector3.Slerp(transform.forward, m_desiredDirection.normalized, m_rotationSpeed * Time.deltaTime); } private void ApplyMovement() { if (!m_recievedInput) return; float forwardRatio = (Vector3.Dot(transform.forward, m_desiredDirection.normalized) + 1) / 2; float speed = m_turnRadius.Evaluate(forwardRatio) * m_playerSpeed; m_controller.Move(transform.forward * speed * Time.deltaTime); } private void LockAxis(Vector3 axis) { transform.position = Vector3.ProjectOnPlane(transform.position, axis); } }