-
Notifications
You must be signed in to change notification settings - Fork 3
/
RotateAroundTarget.cs
65 lines (50 loc) · 1.74 KB
/
RotateAroundTarget.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
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Rotates a Game Object around a target position. You can use this to do targeting like the Dark Souls games.")]
public class RotateAroundTarget : FsmStateAction
{
[RequiredField]
[Tooltip("The game object to rotate. Usually your player character.")]
public FsmOwnerDefault gameObject;
[Tooltip("Vector3 for the target object to rotate around. This is your target object you want to rotate around.")]
[UIHint(UIHint.Variable)]
public FsmVector3 targetPosition;
[Tooltip("Movement on the X axis while targeting. Use the vector from a Get Axis action here.")]
public FsmFloat rotationDirection;
[Tooltip("Repeat every frame.")]
public bool everyFrame;
public override void Reset()
{
gameObject = null;
targetPosition = null;
everyFrame = true;
rotationDirection = null;
}
public override void OnEnter()
{
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
if (everyFrame)
{
DoRotate();
}
}
void DoRotate()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}
// Rotate around target
go.transform.RotateAround(targetPosition.Value, Vector3.up, rotationDirection.Value * Time.deltaTime);
}
}
}