Skip to content

Commit 214b998

Browse files
committed
started update of hinge joint to better refelect the newer prismatic joint style
1 parent 36b7494 commit 214b998

File tree

4 files changed

+51
-120
lines changed

4 files changed

+51
-120
lines changed

Runtime/Scripts/Physics/ZOHingeJoint.cs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Newtonsoft.Json.Linq;
77
using ZO.Util.Extensions;
88
using ZO.Document;
9+
using ZO.Util;
910

1011

1112
namespace ZO.Physics {
@@ -23,7 +24,11 @@ namespace ZO.Physics {
2324
[ExecuteAlways]
2425
public class ZOHingeJoint : MonoBehaviour, ZOSerializationInterface, ZOJointInterface {
2526

26-
[SerializeField] public UnityEngine.HingeJoint _hingeJoint;
27+
public Rigidbody _connectedBody;
28+
public Vector3 _anchor = Vector3.zero;
29+
public Vector3 _axis = Vector3.forward;
30+
31+
[SerializeField] [ZOReadOnlyAttribute] public UnityEngine.HingeJoint _hingeJoint;
2732

2833
/// <summary>
2934
/// The Unity hinge joint linked to this ZOSim hinge joint.
@@ -67,6 +72,39 @@ public Vector3 ConnectedAnchor {
6772
}
6873
}
6974

75+
/// <summary>
76+
/// The connected rigid body. If null then it is the world.
77+
/// </summary>
78+
/// <value></value>
79+
public Rigidbody ConnectedBody {
80+
get {
81+
return UnityHingeJoint.connectedBody;
82+
}
83+
set {
84+
if (UnityHingeJoint.connectedBody != value) {
85+
UnityHingeJoint.connectedBody = value;
86+
}
87+
88+
// update the name
89+
_name = Type;
90+
91+
ZOSimOccurrence occurrence = GetComponent<ZOSimOccurrence>();
92+
if (occurrence) {
93+
_name = _name + "_from_" + occurrence.Name;
94+
}
95+
96+
if (UnityHingeJoint.connectedBody) {
97+
ZOSimOccurrence connected_occurrence = UnityHingeJoint.connectedBody.gameObject.GetComponent<ZOSimOccurrence>();
98+
99+
if (connected_occurrence) {
100+
_name = _name + "_to_" + connected_occurrence.Name;
101+
}
102+
}
103+
104+
}
105+
}
106+
107+
70108
public bool _debug = false;
71109

72110

@@ -123,18 +161,6 @@ public float Effort {
123161
}
124162
}
125163

126-
/// <summary>
127-
/// The connected rigid body. If null then it is the world.
128-
/// </summary>
129-
/// <value></value>
130-
public Rigidbody ConnectedBody {
131-
get {
132-
return UnityHingeJoint.connectedBody;
133-
}
134-
set {
135-
UnityHingeJoint.connectedBody = value;
136-
}
137-
}
138164

139165
/// <summary>
140166
/// The connected ZOSim Occurrence. Being null does not necessarily mean anything.
@@ -193,12 +219,18 @@ private void OnGUI() {
193219
// Quaternion r = Quaternion.Inverse(this.transform.rotation) * ConnectedBody.transform.rotation;
194220
// float angle = ZO.Math.ZOMathUtil.FindQuaternionTwist(r, UnityHingeJoint.axis) * Mathf.Rad2Deg;
195221

196-
GUI.TextField(new Rect(10, 10, 300, 22), this.Name + " Angle: " + (_currentAngleRadians * Mathf.Rad2Deg).ToString("R2")
222+
GUI.TextField(new Rect(10, 10, 400, 22), this.Name + " Angle: " + (Position * Mathf.Rad2Deg).ToString("R2")
197223
+ " Target: " + (UnityHingeJoint.spring.targetPosition * Mathf.Rad2Deg).ToString("R2"));
198224

199225
}
200226
}
201227

228+
private void OnValidate() {
229+
Axis = _axis;
230+
ConnectedBody = _connectedBody;
231+
Anchor = _anchor;
232+
}
233+
202234
#endregion
203235

204236
// private void FixedUpdate() {

Runtime/Scripts/Physics/ZOPrismaticJoint.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,13 @@ protected void OnDrawGizmosSelected() {
288288

289289
Quaternion worldAxisRotation = Quaternion.LookRotation(transform.TransformDirection(Axis));
290290

291-
Vector3 lowerLimit = transform.TransformPoint(Anchor + (JointDirection * JointLimits.LowerLimit));
291+
Vector3 lowerLimit = transform.TransformPoint(Anchor - (Axis * UnityConfigurableJoint.linearLimit.limit));
292+
// Vector3 lowerLimit = transform.TransformPoint(Anchor + (JointDirection * JointLimits.LowerLimit));
292293
Handles.color = Color.red;
293294
Handles.CylinderHandleCap(0, lowerLimit, worldAxisRotation, HandleUtility.GetHandleSize(lowerLimit) * 0.2f, EventType.Repaint);
294295

295-
Vector3 upperLimit = transform.TransformPoint(Anchor + (JointDirection * JointLimits.UpperLimit));
296+
// Vector3 upperLimit = transform.TransformPoint(Anchor + (JointDirection * JointLimits.UpperLimit));
297+
Vector3 upperLimit = transform.TransformPoint(Anchor + (Axis * UnityConfigurableJoint.linearLimit.limit));
296298
Handles.color = Color.blue;
297299
Handles.CylinderHandleCap(0, upperLimit, worldAxisRotation, HandleUtility.GetHandleSize(lowerLimit) * 0.2f, EventType.Repaint);
298300

@@ -324,12 +326,6 @@ private void Reset() {
324326
private void OnValidate() {
325327
SetupPrismaticJointFromConfigurableJoint();
326328
}
327-
// private void OnDestroy() {
328-
// if ((Application.isEditor == true) && (Application.isPlaying == false) && (UnityConfigurableJoint != null) && (Application.isLoadingLevel == false)) {
329-
// DestroyImmediate(UnityConfigurableJoint);
330-
// UnityConfigurableJoint = null;
331-
// }
332-
// }
333329

334330

335331

Runtime/Scripts/Util/GameObject/ZOMouseOrbitCamera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void Start() {
3636

3737
void LateUpdate() {
3838
if (target) {
39-
if (Input.GetMouseButton(0)) {
39+
if (Input.GetMouseButton(0) && Input.GetKey(KeyCode.LeftShift) == false) {
4040
x += Input.GetAxis("Mouse X") * _xSpeed * _distance * 0.02f;
4141
y -= Input.GetAxis("Mouse Y") * _ySpeed * 0.02f;
4242
}

Samples~/ZeroSimSamples/Scenes/PrismaticJoint_test.unity

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,6 @@ GameObject:
15261526
- component: {fileID: 1299972867}
15271527
- component: {fileID: 1299972868}
15281528
- component: {fileID: 1299972870}
1529-
- component: {fileID: 1299972869}
15301529
- component: {fileID: 1299972876}
15311530
- component: {fileID: 1299972875}
15321531
- component: {fileID: 1299972874}
@@ -1572,102 +1571,6 @@ MonoBehaviour:
15721571
m_Name:
15731572
m_EditorClassIdentifier:
15741573
_documentRoot: {fileID: 526221475}
1575-
--- !u!153 &1299972869
1576-
ConfigurableJoint:
1577-
m_ObjectHideFlags: 2
1578-
m_CorrespondingSourceObject: {fileID: 0}
1579-
m_PrefabInstance: {fileID: 0}
1580-
m_PrefabAsset: {fileID: 0}
1581-
m_GameObject: {fileID: 1299972866}
1582-
m_ConnectedBody: {fileID: 1389040765}
1583-
m_ConnectedArticulationBody: {fileID: 0}
1584-
m_Anchor: {x: 0, y: 0.2, z: 0}
1585-
m_Axis: {x: -0, y: -0, z: -1}
1586-
m_AutoConfigureConnectedAnchor: 0
1587-
m_ConnectedAnchor: {x: 0, y: 0, z: 0.17500001}
1588-
serializedVersion: 2
1589-
m_SecondaryAxis: {x: 0, y: 1, z: 0}
1590-
m_XMotion: 1
1591-
m_YMotion: 0
1592-
m_ZMotion: 0
1593-
m_AngularXMotion: 0
1594-
m_AngularYMotion: 0
1595-
m_AngularZMotion: 0
1596-
m_LinearLimitSpring:
1597-
spring: 0
1598-
damper: 0
1599-
m_LinearLimit:
1600-
limit: 0.175
1601-
bounciness: 0
1602-
contactDistance: 0
1603-
m_AngularXLimitSpring:
1604-
spring: 0
1605-
damper: 0
1606-
m_LowAngularXLimit:
1607-
limit: 0
1608-
bounciness: 0
1609-
contactDistance: 0
1610-
m_HighAngularXLimit:
1611-
limit: 0
1612-
bounciness: 0
1613-
contactDistance: 0
1614-
m_AngularYZLimitSpring:
1615-
spring: 0
1616-
damper: 0
1617-
m_AngularYLimit:
1618-
limit: 0
1619-
bounciness: 0
1620-
contactDistance: 0
1621-
m_AngularZLimit:
1622-
limit: 0
1623-
bounciness: 0
1624-
contactDistance: 0
1625-
m_TargetPosition: {x: 0, y: 0, z: 0}
1626-
m_TargetVelocity: {x: 0, y: 0, z: 0}
1627-
m_XDrive:
1628-
serializedVersion: 3
1629-
positionSpring: 0
1630-
positionDamper: 0
1631-
maximumForce: 3.4028233e+38
1632-
m_YDrive:
1633-
serializedVersion: 3
1634-
positionSpring: 0
1635-
positionDamper: 0
1636-
maximumForce: 3.4028233e+38
1637-
m_ZDrive:
1638-
serializedVersion: 3
1639-
positionSpring: 0
1640-
positionDamper: 0
1641-
maximumForce: 3.4028233e+38
1642-
m_TargetRotation: {x: 0, y: 0, z: 0, w: 1}
1643-
m_TargetAngularVelocity: {x: 0, y: 0, z: 0}
1644-
m_RotationDriveMode: 0
1645-
m_AngularXDrive:
1646-
serializedVersion: 3
1647-
positionSpring: 0
1648-
positionDamper: 0
1649-
maximumForce: 3.4028233e+38
1650-
m_AngularYZDrive:
1651-
serializedVersion: 3
1652-
positionSpring: 0
1653-
positionDamper: 0
1654-
maximumForce: 3.4028233e+38
1655-
m_SlerpDrive:
1656-
serializedVersion: 3
1657-
positionSpring: 0
1658-
positionDamper: 0
1659-
maximumForce: 3.4028233e+38
1660-
m_ProjectionMode: 0
1661-
m_ProjectionDistance: 0.1
1662-
m_ProjectionAngle: 180
1663-
m_ConfiguredInWorldSpace: 0
1664-
m_SwapBodies: 0
1665-
m_BreakForce: Infinity
1666-
m_BreakTorque: Infinity
1667-
m_EnableCollision: 1
1668-
m_EnablePreprocessing: 1
1669-
m_MassScale: 1
1670-
m_ConnectedMassScale: 1
16711574
--- !u!54 &1299972870
16721575
Rigidbody:
16731576
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)