summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll/AddForceByCollision.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 17:37:47 +0800
committerchai <215380520@qq.com>2024-03-13 17:37:47 +0800
commit54c872fa42b1ba0fdbcfe812b80bb8eb0cfe108f (patch)
tree5d7e1b1b33ef67f147f92a912e2ab371e83ec490 /_ActiveRagdoll/AddForceByCollision.cs
parent134f1deb971b0514a26e04e23926f91983a5497f (diff)
*misc
Diffstat (limited to '_ActiveRagdoll/AddForceByCollision.cs')
-rw-r--r--_ActiveRagdoll/AddForceByCollision.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/_ActiveRagdoll/AddForceByCollision.cs b/_ActiveRagdoll/AddForceByCollision.cs
new file mode 100644
index 0000000..8392efa
--- /dev/null
+++ b/_ActiveRagdoll/AddForceByCollision.cs
@@ -0,0 +1,34 @@
+using UnityEngine;
+
+public class AddForceByCollision : MonoBehaviour
+{
+ public Rigidbody rig;
+
+ public float amout;
+
+ private void Start()
+ {
+ }
+
+ private void Update()
+ {
+ }
+
+ private void OnCollisionEnter(Collision collision)
+ {
+ Collide(collision);
+ }
+
+ private void OnCollisionStay(Collision collision)
+ {
+ Collide(collision);
+ }
+
+ private void Collide(Collision collision)
+ {
+ if (collision.gameObject.layer == 9)
+ {
+ rig.AddForce(collision.contacts[0].normal * collision.impactForceSum.magnitude * amout, ForceMode.Acceleration);
+ }
+ }
+}