-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathClubSpell.cs
78 lines (63 loc) · 1.76 KB
/
ClubSpell.cs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections;
using UnityEngine;
using Landfall.TABS;
public class ClubSpell : TargetableEffect
{
public AnimationCurve upCurve;
public AnimationCurve forceCurve;
public float force;
private float RockStartY;
private Rigidbody Rig;
private Vector3 Direction;
private Vector3 StartPos;
public float prediction = 1f;
private Rigidbody Target;
public void Start()
{
StartPos = transform.position;
}
private IEnumerator Go()
{
var t2 = upCurve.keys[upCurve.keys.Length - 1].time;
var c2 = 0f;
while (c2 < t2)
{
c2 += Time.deltaTime;
Rig.transform.localPosition = new Vector3(0f, upCurve.Evaluate(c2) + RockStartY, 0f);
yield return null;
}
Rig.isKinematic = false;
t2 = forceCurve.keys[forceCurve.keys.Length - 1].time;
c2 = 0f;
GetDirection(Rig.position, Target.position, Target);
Rig.useGravity = false;
while (c2 < t2)
{
c2 += Time.deltaTime;
Rig.velocity = Direction * (forceCurve.Evaluate(c2) * force);
yield return null;
}
Rig.useGravity = true;
}
public override void DoEffect(Transform startPoint, Transform endPoint)
{
}
public override void DoEffect(Vector3 startPoint, Vector3 endPoint, Rigidbody targetRig = null)
{
Target = targetRig;
Rig = GetComponentInChildren<Rigidbody>();
RockStartY = Rig.transform.localPosition.y;
StartCoroutine(Go());
}
public void DoSpell()
{
var enemyMainRig = transform.root.GetComponent<Unit>().data.targetMainRig;
DoEffect(StartPos, enemyMainRig.position, enemyMainRig);
}
private void GetDirection(Vector3 startPoint, Vector3 endPoint, Rigidbody targetRig)
{
var vector = endPoint;
vector += targetRig.velocity * (prediction * 0.1f * Vector3.Distance(startPoint, vector));
Direction = (vector - startPoint).normalized;
}
}