blob: 9464c979d6ad011a27bb971d275e49bae8f17a41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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);
}
}
}
|