From f460bb84e8f6bbc86f445465bcc167622b71f0df Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 7 Apr 2020 19:31:56 +0900 Subject: [PATCH] Implement starboard alignment 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... --- Source/DisposablePad/DisposablePad.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/DisposablePad/DisposablePad.cs b/Source/DisposablePad/DisposablePad.cs index 8ea3719d..167470de 100644 --- a/Source/DisposablePad/DisposablePad.cs +++ b/Source/DisposablePad/DisposablePad.cs @@ -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); }