diff options
author | chai <215380520@qq.com> | 2024-03-13 17:37:47 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 17:37:47 +0800 |
commit | 54c872fa42b1ba0fdbcfe812b80bb8eb0cfe108f (patch) | |
tree | 5d7e1b1b33ef67f147f92a912e2ab371e83ec490 /_ActiveRagdoll/AddForceToTarget.cs | |
parent | 134f1deb971b0514a26e04e23926f91983a5497f (diff) |
*misc
Diffstat (limited to '_ActiveRagdoll/AddForceToTarget.cs')
-rw-r--r-- | _ActiveRagdoll/AddForceToTarget.cs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/_ActiveRagdoll/AddForceToTarget.cs b/_ActiveRagdoll/AddForceToTarget.cs new file mode 100644 index 0000000..9464c97 --- /dev/null +++ b/_ActiveRagdoll/AddForceToTarget.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +public class AddForceToTarget : MonoBehaviour +{ + public AnimationCurve forceByRangeCurve; + + public Rigidbody target; + + public float force; + + private Transform head; + + private void Start() + { + head = GetComponentInChildren<Head>().transform; + } + + private void FixedUpdate() + { + float num = forceByRangeCurve.Evaluate(Vector3.Distance(head.position, target.position)) * force; + if (num > 0f) + { + target.AddForce((head.position - target.position).normalized * num, ForceMode.Force); + } + } +} |