diff options
| author | chai <215380520@qq.com> | 2024-05-20 22:36:58 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-20 22:36:58 +0800 |
| commit | a22c505984697881f5f911a165ee022087b69e09 (patch) | |
| tree | d3c030aef1ae9b8a01c889dd2902bb1e3324e72b /Thronefall_1_0/Decompile/PlayerMovement.cs | |
| parent | 4a4cc82d069b26bc4d4532e73860f86b211ca239 (diff) | |
Diffstat (limited to 'Thronefall_1_0/Decompile/PlayerMovement.cs')
| -rw-r--r-- | Thronefall_1_0/Decompile/PlayerMovement.cs | 152 |
1 files changed, 0 insertions, 152 deletions
diff --git a/Thronefall_1_0/Decompile/PlayerMovement.cs b/Thronefall_1_0/Decompile/PlayerMovement.cs deleted file mode 100644 index db7c18a..0000000 --- a/Thronefall_1_0/Decompile/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<CharacterController>(); - input = ReInput.players.GetPlayer(0); - rvoController = GetComponent<RVOController>(); - hp = GetComponent<Hp>(); - 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; - } -} |
