/
WheelColliderGetWorldPose.cs
99 lines (78 loc) · 2.09 KB
/
WheelColliderGetWorldPose.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.
/*--- __ECO__ __ACTION__ ---*/
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Gets the world space pose of the wheel accounting for ground contact, suspension limits, steer angle, and rotation angle (angles in degrees).")]
public class WheelColliderGetWorldPose : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(WheelCollider))]
[Tooltip("The GameObject with the WheelCollider component.")]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
[Tooltip("The WheelCollider World Position")]
public FsmVector3 position;
[UIHint(UIHint.Variable)]
[Tooltip("The WheelCollider World rotation")]
public FsmQuaternion rotation;
[Tooltip("Matches the wheel Collider world Position and Rotation")]
public FsmOwnerDefault transform;
[Tooltip("Repeat every frame.")]
public bool everyFrame;
WheelCollider _component;
Vector3 _position;
Quaternion _rotation;
GameObject _dummy;
public override void Reset()
{
gameObject = null;
position = null;
rotation = null;
transform = new FsmOwnerDefault();
transform.OwnerOption = OwnerDefaultOption.SpecifyGameObject;
transform.GameObject = new FsmGameObject(){UseVariable=true};
everyFrame = true;
}
public override void OnEnter()
{
GameObject _go = Fsm.GetOwnerDefaultTarget(gameObject);
if (_go!=null)
{
_component = _go.GetComponent<WheelCollider>();
}
GetWorldPose();
if (!everyFrame)
{
Finish();
}
}
public override void OnUpdate()
{
GetWorldPose();
}
void GetWorldPose()
{
if (_component==null)
{
return;
}
_component.GetWorldPose(out _position,out _rotation);
if (!position.IsNone)
{
position.Value = _position;
}
if (!rotation.IsNone)
{
rotation.Value = _rotation;
}
_dummy = Fsm.GetOwnerDefaultTarget(gameObject);
if (_dummy!=null)
{
_dummy.transform.position = _position;
_dummy.transform.rotation = _rotation;
}
}
}
}