summaryrefslogtreecommitdiff
path: root/Balance.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:38:18 +0800
committerchai <215380520@qq.com>2024-03-13 11:38:18 +0800
commit134f1deb971b0514a26e04e23926f91983a5497f (patch)
treed790681bb000c07abae9f557a7d0ef2442fac467 /Balance.cs
parent6ce8b9e22fc13be34b442c7b6af48b42cd44275a (diff)
* move
Diffstat (limited to 'Balance.cs')
-rw-r--r--Balance.cs101
1 files changed, 0 insertions, 101 deletions
diff --git a/Balance.cs b/Balance.cs
deleted file mode 100644
index dc9ae60..0000000
--- a/Balance.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using UnityEngine;
-
-public class Balance : MonoBehaviour
-{
- private Rigidbody handLeft;
-
- private Rigidbody handRight;
-
- private Rigidbody footLeft;
-
- private Rigidbody footRight;
-
- private Rigidbody hip;
-
- private Vector3 centerOfMass;
-
- private Rigidbody[] allRigs;
-
- public float[] balanceForce;
-
- public float[] footCenterForces;
-
- private AnimationHandler animationHandler;
-
- private PlayerDeath death;
-
- private Strength str;
-
- private float muscleMultiplier;
-
- private void Start()
- {
- death = GetComponent<PlayerDeath>();
- str = GetComponent<Strength>();
- allRigs = GetComponentsInChildren<Rigidbody>();
- HandLeft componentInChildren = GetComponentInChildren<HandLeft>();
- if ((bool)componentInChildren)
- {
- handLeft = componentInChildren.GetComponent<Rigidbody>();
- }
- HandRight componentInChildren2 = GetComponentInChildren<HandRight>();
- if ((bool)componentInChildren2)
- {
- handRight = componentInChildren2.GetComponent<Rigidbody>();
- }
- footLeft = GetComponentInChildren<KneeLeft>().GetComponent<Rigidbody>();
- footRight = GetComponentInChildren<KneeRight>().GetComponent<Rigidbody>();
- hip = GetComponentInChildren<Hip>().GetComponent<Rigidbody>();
- animationHandler = GetComponent<AnimationHandler>();
- }
-
- private void FixedUpdate()
- {
- if (!death.dead)
- {
- muscleMultiplier = str.strength;
- centerOfMass = Vector3.zero;
- Rigidbody[] array = allRigs;
- foreach (Rigidbody rigidbody in array)
- {
- centerOfMass += rigidbody.worldCenterOfMass;
- }
- centerOfMass /= (float)allRigs.Length;
- centerOfMass.y = 0f;
- BalanceLegs();
- CenterLegs();
- }
- }
-
- private void CenterLegs()
- {
- Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f;
- Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f;
- Vector3 vector3 = vector;
- if (vector.y + 0.3f < hip.worldCenterOfMass.y)
- {
- vector3.y = 0f;
- footLeft.AddForceAtPosition((centerOfMass - vector3) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector, ForceMode.Acceleration);
- }
- Vector3 vector4 = vector2;
- if (vector4.y + 0.3f < hip.worldCenterOfMass.y)
- {
- vector4.y = 0f;
- footRight.AddForceAtPosition((centerOfMass - vector4) * muscleMultiplier * footCenterForces[animationHandler.animationState], vector2, ForceMode.Acceleration);
- }
- }
-
- private void BalanceLegs()
- {
- Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f;
- Vector3 vector2 = footRight.transform.position + footRight.transform.forward * 0.5f;
- Vector3 vector3 = (vector + vector2) / 2f;
- if (!(vector3.y + 0.3f > hip.worldCenterOfMass.y))
- {
- vector3.y = 0f;
- Vector3 vector4 = centerOfMass - vector3;
- footLeft.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector, ForceMode.Acceleration);
- footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration);
- }
- }
-}