From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/PlayerMovement.cs | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 GameCode/PlayerMovement.cs (limited to 'GameCode/PlayerMovement.cs') diff --git a/GameCode/PlayerMovement.cs b/GameCode/PlayerMovement.cs new file mode 100644 index 0000000..d3af00e --- /dev/null +++ b/GameCode/PlayerMovement.cs @@ -0,0 +1,71 @@ +using UnityEngine; + +public class PlayerMovement : MonoBehaviour +{ + public float force; + + public float airControl = 0.3f; + + public float extraDrag; + + public float extraAngularDrag; + + public float wallGrabDrag; + + private CharacterData data; + + private CharacterStatModifiers stats; + + private float multiplier = 1f; + + private void Start() + { + data = GetComponent(); + stats = GetComponent(); + } + + private void FixedUpdate() + { + if (!data.isPlaying) + { + return; + } + Move(data.input.direction); + if (data.isWallGrab && data.wallDistance < 0.7f) + { + Vector2 velocity = data.playerVel.velocity; + if (data.input.direction.y >= 0f) + { + _ = data.input.direction.x; + _ = 0f; + } + data.playerVel.velocity = velocity; + } + data.playerVel.velocity -= data.playerVel.velocity * TimeHandler.timeScale * 0.01f * 0.1f * extraDrag * multiplier; + data.playerVel.angularVelocity -= data.playerVel.angularVelocity * TimeHandler.timeScale * 0.01f * 0.1f * extraAngularDrag * multiplier; + } + + private void Update() + { + } + + public void Move(Vector2 direction) + { + UpdateMultiplier(); + if (!data.isStunned) + { + direction.y = Mathf.Clamp(direction.y, -1f, 0f); + direction.y *= 2f; + data.playerVel.AddForce(direction * TimeHandler.timeScale * (1f - stats.GetSlow()) * stats.movementSpeed * force * data.playerVel.mass * 0.01f * multiplier, ForceMode2D.Force); + } + } + + private void UpdateMultiplier() + { + multiplier = 1f; + if (!data.isGrounded) + { + multiplier = airControl; + } + } +} -- cgit v1.1-26-g67d0