summaryrefslogtreecommitdiff
path: root/ActiveRagdoll/Assets/Scripts/JointMotion.cs
diff options
context:
space:
mode:
Diffstat (limited to 'ActiveRagdoll/Assets/Scripts/JointMotion.cs')
-rw-r--r--ActiveRagdoll/Assets/Scripts/JointMotion.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/ActiveRagdoll/Assets/Scripts/JointMotion.cs b/ActiveRagdoll/Assets/Scripts/JointMotion.cs
new file mode 100644
index 0000000..50d043f
--- /dev/null
+++ b/ActiveRagdoll/Assets/Scripts/JointMotion.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.Events;
+
+[Serializable]
+public class MotionCondition : SerializableCallback<bool> { }
+
+[Serializable]
+public class JointMotion
+{
+ #region 序列化
+ public string desc;
+ public JointMotionInfo info;
+ public MotionCondition condition;
+ #endregion
+
+ #region 私有字段
+ public Rigidbody m_Rig;
+ #endregion
+
+ public void Animate(Rigidbody hip)
+ {
+ if (condition.target != null && condition.Invoke() == false)
+ return;
+
+ Vector3 dir = Vector3.zero;
+
+ if (info.direction == JointMotionInfo.MoveDirection.Swing)
+ {
+ dir = m_Rig.transform.right;
+ }
+
+ if (info.direction == JointMotionInfo.MoveDirection.FollowHip)
+ {
+ dir = hip.velocity.normalized;
+ }
+
+ if (info.type == JointMotionInfo.MotionType.Torque)
+ {
+ m_Rig.AddTorque(dir * Time.deltaTime * info.forceMultiplier, ForceMode.Acceleration);
+ }
+
+ if (info.type == JointMotionInfo.MotionType.Force)
+ {
+ m_Rig.AddForce(dir * Time.deltaTime * info.forceMultiplier, ForceMode.Acceleration);
+ }
+ }
+
+}