From 8b1fc7063b387542803c6bc214ccf8acb32870bd Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Sun, 19 May 2024 16:46:27 +0800 Subject: * rename --- Thronefall_1_0/GameCode/PlayerMovement.cs | 152 ------------------------------ 1 file changed, 152 deletions(-) delete mode 100644 Thronefall_1_0/GameCode/PlayerMovement.cs (limited to 'Thronefall_1_0/GameCode/PlayerMovement.cs') diff --git a/Thronefall_1_0/GameCode/PlayerMovement.cs b/Thronefall_1_0/GameCode/PlayerMovement.cs deleted file mode 100644 index db7c18a..0000000 --- a/Thronefall_1_0/GameCode/PlayerMovement.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System.Collections; -using Pathfinding.RVO; -using Rewired; -using UnityEngine; - -[RequireComponent(typeof(CharacterController))] -[RequireComponent(typeof(RVOController))] -public class PlayerMovement : MonoBehaviour -{ - public float speed = 4f; - - public float sprintSpeed = 12f; - - public Transform meshParent; - - public float maxMeshRotationSpeed = 360f; - - public Animator meshAnimator; - - private Hp hp; - - private Transform viewTransform; - - private CharacterController controller; - - private Player input; - - private Quaternion desiredMeshRotation; - - private RVOController rvoController; - - private float yVelocity; - - private bool heavyArmorEquipped; - - private bool racingHorseEquipped; - - private bool moving; - - private bool sprinting; - - private bool sprintingToggledOn; - - public static PlayerMovement instance; - - [SerializeField] - private Equippable heavyArmorPerk; - - [SerializeField] - private Equippable warHorsePerk; - - private Vector3 velocity; - - public bool Moving => moving; - - public bool Sprinting => sprinting; - - public Vector3 Velocity => velocity; - - private void Awake() - { - instance = this; - } - - public void TeleportTo(Vector3 _position) - { - controller.enabled = false; - controller.transform.position = _position; - StartCoroutine(EnableControllerNextFrame(controller)); - } - - private void Start() - { - PlayerManager.RegisterPlayer(this); - viewTransform = Camera.main.transform; - controller = GetComponent(); - input = ReInput.players.GetPlayer(0); - rvoController = GetComponent(); - hp = GetComponent(); - heavyArmorEquipped = PerkManager.IsEquipped(heavyArmorPerk); - racingHorseEquipped = PerkManager.IsEquipped(warHorsePerk); - } - - private void Update() - { - Vector2 vector = new Vector2(input.GetAxis("Move Vertical"), input.GetAxis("Move Horizontal")); - if (LocalGamestate.Instance.PlayerFrozen) - { - vector = Vector2.zero; - } - Vector3 normalized = Vector3.ProjectOnPlane(viewTransform.forward, Vector3.up).normalized; - Vector3 normalized2 = Vector3.ProjectOnPlane(viewTransform.right, Vector3.up).normalized; - velocity = Vector3.zero; - velocity += normalized * vector.x; - velocity += normalized2 * vector.y; - velocity = Vector3.ClampMagnitude(velocity, 1f); - if (input.GetButtonDown("Sprint Toggle")) - { - sprintingToggledOn = !sprintingToggledOn; - } - if (sprintingToggledOn && input.GetButton("Sprint")) - { - sprintingToggledOn = false; - } - sprinting = (input.GetButton("Sprint") || sprintingToggledOn) && hp.HpPercentage >= 1f; - velocity *= (sprinting ? sprintSpeed : speed); - if (heavyArmorEquipped && DayNightCycle.Instance.CurrentTimestate == DayNightCycle.Timestate.Night) - { - velocity *= PerkManager.instance.heavyArmor_SpeedMultiplyer; - } - if (racingHorseEquipped) - { - velocity *= PerkManager.instance.racingHorse_SpeedMultiplyer; - } - rvoController.velocity = velocity; - moving = velocity.sqrMagnitude > 0.1f; - if (moving) - { - desiredMeshRotation = Quaternion.LookRotation(velocity.normalized, Vector3.up); - } - if (desiredMeshRotation != meshParent.rotation) - { - meshParent.rotation = Quaternion.RotateTowards(meshParent.rotation, desiredMeshRotation, maxMeshRotationSpeed * Time.deltaTime); - } - meshAnimator.SetBool("Moving", moving); - meshAnimator.SetBool("Sprinting", sprinting); - if (controller.enabled) - { - if (controller.isGrounded) - { - yVelocity = 0f; - } - else - { - yVelocity += -9.81f * Time.deltaTime; - } - velocity += Vector3.up * yVelocity; - controller.Move(velocity * Time.deltaTime); - } - } - - private void OnDisable() - { - meshAnimator.SetBool("Moving", value: false); - } - - private IEnumerator EnableControllerNextFrame(CharacterController controller) - { - yield return new WaitForEndOfFrame(); - controller.enabled = true; - } -} -- cgit v1.1-26-g67d0