summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll/Balance.cs
diff options
context:
space:
mode:
Diffstat (limited to '_ActiveRagdoll/Balance.cs')
-rw-r--r--_ActiveRagdoll/Balance.cs47
1 files changed, 31 insertions, 16 deletions
diff --git a/_ActiveRagdoll/Balance.cs b/_ActiveRagdoll/Balance.cs
index dc9ae60..06953fa 100644
--- a/_ActiveRagdoll/Balance.cs
+++ b/_ActiveRagdoll/Balance.cs
@@ -1,32 +1,31 @@
using UnityEngine;
+//Player Balance 动作-控制身体平衡
public class Balance : MonoBehaviour
{
- private Rigidbody handLeft;
-
+ #region rigs
+ private Rigidbody handLeft;
private Rigidbody handRight;
-
- private Rigidbody footLeft;
-
- private Rigidbody footRight;
-
+ private Rigidbody footLeft; // kneeLeft
+ private Rigidbody footRight; // kneeRight
private Rigidbody hip;
+ #endregion
- private Vector3 centerOfMass;
+ private Vector3 centerOfMass; // 5.0759, 0, -7.2038
- private Rigidbody[] allRigs;
+ private Rigidbody[] allRigs;//所有14个parts
- public float[] balanceForce;
+ public float[] balanceForce; // 50 30 30 30
- public float[] footCenterForces;
+ public float[] footCenterForces; // 50 20 20 20
- private AnimationHandler animationHandler;
+ private AnimationHandler animationHandler; // 当前动作编号
private PlayerDeath death;
private Strength str;
- private float muscleMultiplier;
+ private float muscleMultiplier; // 1
private void Start()
{
@@ -90,11 +89,27 @@ public class Balance : MonoBehaviour
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 pos = vector3;
+ pos.y += 0.3f;
+
+ 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);
+ Vector3 vector4 = centerOfMass - vector3; // centerOfMass是xoz平面,不含y
+ REPL.footCenter.GetComponent<DebugRigidBody>().customDraw = () =>
+ {
+ Draw.Sphere(vector, 0.05f);
+ Draw.Sphere(vector2, 0.05f);
+ Draw.Sphere(pos, 0.05f);
+ Draw.Sphere(vector3, 0.05f);
+ Draw.Sphere(hip.worldCenterOfMass, 0.2f);
+
+ Draw.Sphere(centerOfMass, 0.05f);
+ Draw.Line3D(vector3 + new Vector3(0, footLeft.transform.position.y, 0), centerOfMass + new Vector3(0, footLeft.transform.position.y, 0));
+ };
+
+ footLeft.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector, ForceMode.Acceleration);
footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration);
}
}