summaryrefslogtreecommitdiff
path: root/GameCode/PlayerVelocity.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/PlayerVelocity.cs
+ init
Diffstat (limited to 'GameCode/PlayerVelocity.cs')
-rw-r--r--GameCode/PlayerVelocity.cs82
1 files changed, 82 insertions, 0 deletions
diff --git a/GameCode/PlayerVelocity.cs b/GameCode/PlayerVelocity.cs
new file mode 100644
index 0000000..47822f6
--- /dev/null
+++ b/GameCode/PlayerVelocity.cs
@@ -0,0 +1,82 @@
+using UnityEngine;
+
+public class PlayerVelocity : MonoBehaviour
+{
+ internal bool simulated = true;
+
+ internal bool isKinematic;
+
+ internal Vector2 velocity;
+
+ internal float mass = 100f;
+
+ internal float angularVelocity;
+
+ private CharacterData data;
+
+ public Vector2 position
+ {
+ get
+ {
+ return base.transform.position;
+ }
+ set
+ {
+ base.transform.position = value;
+ }
+ }
+
+ internal void AddTorque(float v)
+ {
+ }
+
+ private void Start()
+ {
+ data = GetComponent<CharacterData>();
+ }
+
+ private void FixedUpdate()
+ {
+ if (data.isPlaying)
+ {
+ if (isKinematic)
+ {
+ velocity *= 0f;
+ }
+ if (simulated && !isKinematic)
+ {
+ velocity += Vector2.down * Time.fixedDeltaTime * TimeHandler.timeScale * 20f;
+ base.transform.position += Time.fixedDeltaTime * TimeHandler.timeScale * (Vector3)velocity;
+ base.transform.position = new Vector3(base.transform.position.x, base.transform.position.y, 0f);
+ }
+ }
+ }
+
+ internal void AddForce(Vector2 force, ForceMode2D forceMode)
+ {
+ if (forceMode == ForceMode2D.Force)
+ {
+ force *= 0.02f;
+ }
+ else
+ {
+ force *= 1f;
+ }
+ velocity += force / mass;
+ }
+
+ internal void AddForce(Vector3 force, ForceMode2D forceMode)
+ {
+ AddForce((Vector2)force, forceMode);
+ }
+
+ internal void AddForce(Vector2 force)
+ {
+ AddForce(force, ForceMode2D.Force);
+ }
+
+ internal void AddForce(Vector3 force)
+ {
+ AddForce((Vector2)force, ForceMode2D.Force);
+ }
+}