summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll/Balance.cs
diff options
context:
space:
mode:
Diffstat (limited to '_ActiveRagdoll/Balance.cs')
-rw-r--r--_ActiveRagdoll/Balance.cs42
1 files changed, 28 insertions, 14 deletions
diff --git a/_ActiveRagdoll/Balance.cs b/_ActiveRagdoll/Balance.cs
index 06953fa..f034290 100644
--- a/_ActiveRagdoll/Balance.cs
+++ b/_ActiveRagdoll/Balance.cs
@@ -1,6 +1,6 @@
using UnityEngine;
-//Player Balance 动作-控制身体平衡
+//Player Balance 动作-控制双脚的位置,让双脚和双脚的中点尽可能和重心在水平的投影重合
public class Balance : MonoBehaviour
{
#region rigs
@@ -66,6 +66,7 @@ public class Balance : MonoBehaviour
}
}
+ // 让双脚尽量靠近重心的水平投影
private void CenterLegs()
{
Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f;
@@ -84,6 +85,7 @@ public class Balance : MonoBehaviour
}
}
+ // 让双脚的中点尽量和重心的水平投影重合
private void BalanceLegs()
{
Vector3 vector = footLeft.transform.position + footLeft.transform.forward * 0.5f;
@@ -92,25 +94,37 @@ public class Balance : MonoBehaviour
Vector3 pos = vector3;
pos.y += 0.3f;
+ Vector3 vector03 = vector3;
if (!(vector3.y + 0.3f > hip.worldCenterOfMass.y))
{
vector3.y = 0f;
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));
- };
+
+ REPL.footCenter.GetComponent<DebugRigidBody>().customDraw = () =>
+ {
+ //return;
+
+ Draw.Sphere(vector, 0.05f);
+ Draw.Sphere(vector2, 0.05f);
+
+ Draw.color = Color.red;
+ Draw.Sphere(pos, 0.05f);
+ Draw.Sphere(vector03, 0.05f);
+ Draw.color = Color.white;
+
+ Draw.Sphere(hip.worldCenterOfMass, 0.2f);
+
+ Draw.Sphere(centerOfMass, 0.05f);
+
+ Draw.color = Color.green;
+ Draw.Line3D(vector, vector + vector4);
+ Draw.Line3D(vector2, vector2 + vector4);
+ Draw.color = Color.white;
+ };
footLeft.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector, ForceMode.Acceleration);
- footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration);
- }
+ footRight.AddForceAtPosition(vector4 * muscleMultiplier * balanceForce[animationHandler.animationState], vector2, ForceMode.Acceleration);
+ };
}
}