-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathKnockBackPositionFinder.cs
53 lines (41 loc) · 1.67 KB
/
KnockBackPositionFinder.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
//FrankenCopyCoded by MDS
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Keywords: knockback vector3 cast
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Vector3)]
[Tooltip("Gets the position to knock an object back to on impact. Input a hitPosition and hitNormal from a cast on the projectile that hits the object. The Y axis is ignored. You can easily add it back.")]
public class KnockBackPositionFinder : FsmStateAction
{
public FsmVector3 hitPoint;
public FsmVector3 hitNormal;
public FsmFloat KnockBackDistance;
public FsmVector3 knockBackPosition;
private Vector3 preKnock;
private Ray Ayray;
public bool everyFrame;
public override void Reset()
{
hitNormal = null;
hitPoint = null;
knockBackPosition = null;
KnockBackDistance = null;
everyFrame = false;
}
public override void OnEnter()
{
Ayray = new Ray(hitPoint.Value - hitNormal.Value * 1, hitNormal.Value * -1);
preKnock = Ayray.GetPoint(KnockBackDistance.Value);
knockBackPosition.Value = new Vector3(preKnock.x, 0, preKnock.z);
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
Ayray = new Ray(hitPoint.Value - hitNormal.Value * 1, hitNormal.Value * -1);
preKnock = Ayray.GetPoint(KnockBackDistance.Value);
knockBackPosition.Value = new Vector3(preKnock.x, 0, preKnock.z);
}
}
}