blob: 19b6b67abbbeccc3f86895a346a598967bf22142 (
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
using UnityEngine;
public class TracerTarget : MonoBehaviour
{
private MoveTransform move;
public bool hasPos;
public float drag;
public float spring;
public AnimationCurve curve;
public float cosScale = 1f;
public float cosAmount;
private float random;
private float c;
private bool done;
private Vector3 tPos;
private Vector3 upDir;
private MoveTransform mTrans;
private void Start()
{
move = GetComponent<MoveTransform>();
random = Random.Range(0f, 1000f);
SetPos(base.transform.forward * 100f, base.transform.up, null);
}
private void Update()
{
float num = 1f;
if ((bool)mTrans)
{
num += mTrans.velocity.magnitude * 0.1f;
}
if ((bool)mTrans && !done)
{
tPos += base.transform.forward + base.transform.forward * 10f;
}
c += TimeHandler.deltaTime;
if (hasPos)
{
move.velocity += cosAmount * Mathf.Cos((Time.time + random) * cosScale) * upDir * CappedDeltaTime.time / num;
move.velocity += (tPos - base.transform.position).normalized * spring * CappedDeltaTime.time * curve.Evaluate(c) * num;
move.velocity -= move.velocity * CappedDeltaTime.time * drag * curve.Evaluate(c);
}
}
public void SetPos(Vector3 targetPos, Vector3 up, MoveTransform move)
{
mTrans = move;
hasPos = true;
tPos = targetPos;
upDir = up;
}
}
|