summaryrefslogtreecommitdiff
path: root/GenericForceMovement.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /GenericForceMovement.cs
+init
Diffstat (limited to 'GenericForceMovement.cs')
-rw-r--r--GenericForceMovement.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/GenericForceMovement.cs b/GenericForceMovement.cs
new file mode 100644
index 0000000..4c8160f
--- /dev/null
+++ b/GenericForceMovement.cs
@@ -0,0 +1,40 @@
+using UnityEngine;
+
+public class GenericForceMovement : MonoBehaviour
+{
+ public Vector3 movementDirection;
+
+ public float forceMultiplier = 1f;
+
+ public MovementRig[] rigs;
+
+ public bool useGroundedMultiplier;
+
+ private CollisionChecker[] checkers;
+
+ private void Start()
+ {
+ checkers = GetComponentsInChildren<CollisionChecker>();
+ }
+
+ private void FixedUpdate()
+ {
+ float num = 1f;
+ if (useGroundedMultiplier)
+ {
+ num = 0f;
+ for (int i = 0; i < checkers.Length; i++)
+ {
+ if (checkers[i].sinceGrounded < 0.1f)
+ {
+ num += 1f / (float)checkers.Length;
+ }
+ }
+ }
+ MovementRig[] array = rigs;
+ foreach (MovementRig movementRig in array)
+ {
+ movementRig.rig.AddForce(movementDirection * num * forceMultiplier * movementRig.multiplier, ForceMode.Acceleration);
+ }
+ }
+}