Skip to content

Commit

Permalink
Implement starboard alignment
Browse files Browse the repository at this point in the history
This applies when the root part's forward axis is aligned with the node
axis: instead of keeping up as up, the micro pad keeps starboard as
starboard. Except there's a minor bug...
  • Loading branch information
taniwha committed Apr 7, 2020
1 parent fbe29fd commit f460bb8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Source/DisposablePad/DisposablePad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,19 @@ public void SetShipTransform (Transform shipTransform, Part rootPart)
Vector3 nodeAxis = rootXform.TransformDirection(n.orientation);
Vector3 forward = rootXform.forward;
float fwdDot = Vector3.Dot (forward, nodeAxis);
Debug.Log ($"[EL] nodeAxis: {nodeAxis}");
Debug.Log ($"[EL] rotation: {rootXform.rotation} right:{rootXform.right} forward:{rootXform.forward} up:{rootXform.up}");
if (Mathf.Abs (fwdDot) < 0.866f) {
Debug.Log ($"[EL] nodeAxis: {nodeAxis}");
Debug.Log ($"[EL] rotation: {rootXform.rotation} right:{rootXform.right} forward:{rootXform.forward} up:{rootXform.up}");
rot = Quaternion.LookRotation (nodeAxis, forward);
rot = Quaternion.Inverse (rot);
Debug.Log ($"[EL] {rot}");
rot = Quaternion.LookRotation (Vector3.up, -Vector3.forward) * rot;
Debug.Log ($"[EL] {Quaternion.LookRotation (Vector3.up, -Vector3.forward)}");
} else {
rot = Quaternion.FromToRotation (nodeAxis, Vector3.up);
rot = Quaternion.LookRotation (nodeAxis, rootXform.right);
rot = Quaternion.Inverse (rot);
Debug.Log ($"[EL] {rot}");
rot = new Quaternion (-0.5f, -0.5f, -0.5f, 0.5f) * rot;
}
pos = rootXform.TransformVector (n.position);
}
Expand Down

0 comments on commit f460bb8

Please sign in to comment.