-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHingeJointTarget.cs
More file actions
61 lines (51 loc) · 1.96 KB
/
HingeJointTarget.cs
File metadata and controls
61 lines (51 loc) · 1.96 KB
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
using UnityEngine;
using System.Collections;
public class HingeJointTarget : MonoBehaviour
{
public HingeJoint hj;
public Transform target;
[Tooltip("Only use one of these values at a time. Toggle invert if the rotation is backwards.")]
public bool x, y, z, invert;
void Update()
{
if (hj != null)
{
if (x)
{
JointSpring js;
js = hj.spring;
js.targetPosition = target.transform.localEulerAngles.x;
if (js.targetPosition > 180)
js.targetPosition = js.targetPosition - 360;
if (invert)
js.targetPosition = js.targetPosition * -1;
js.targetPosition = Mathf.Clamp(js.targetPosition, hj.limits.min + 5, hj.limits.max - 5);
hj.spring = js;
}
if (y)
{
JointSpring js;
js = hj.spring;
js.targetPosition = target.transform.localEulerAngles.y;
if (js.targetPosition > 180)
js.targetPosition = js.targetPosition - 360;
if (invert)
js.targetPosition = js.targetPosition * -1;
js.targetPosition = Mathf.Clamp(js.targetPosition, hj.limits.min + 5, hj.limits.max - 5);
hj.spring = js;
}
if (z)
{
JointSpring js;
js = hj.spring;
js.targetPosition = target.transform.localEulerAngles.z;
if (js.targetPosition > 180)
js.targetPosition = js.targetPosition - 360;
if (invert)
js.targetPosition = js.targetPosition * -1;
js.targetPosition = Mathf.Clamp(js.targetPosition, hj.limits.min + 5, hj.limits.max - 5);
hj.spring = js;
}
}
}
}