diff --git a/Source/InternalParentConstraint.cs b/Source/InternalParentConstraint.cs new file mode 100644 index 00000000..e0ae16df --- /dev/null +++ b/Source/InternalParentConstraint.cs @@ -0,0 +1,36 @@ +using System; +using UnityEngine; + +public class ELInternalParentConstraint : InternalModule +{ + [KSPField] + public string parentTransformName; + + Transform parentTransform; + + public override void OnAwake () + { + if (part == null) { + return; + } + if (!String.IsNullOrEmpty (parentTransformName)) { + parentTransform = part.FindModelTransform (parentTransformName); + } + if (parentTransform == null) { + Debug.Log ($"[ELInternalParentConstraint] could not find {parentTransformName}"); + } + } + + void Update () + { + if (parentTransform == null) { + return; + } + Vector3 pos = parentTransform.position; + Quaternion rot = parentTransform.rotation; + + var xform = internalModel.transform; + xform.position = InternalSpace.WorldToInternal (pos); + xform.rotation = InternalSpace.WorldToInternal (rot) * Quaternion.Euler(90, 180, 0); + } +} diff --git a/Source/Makefile b/Source/Makefile index 3df6fc6e..399f500b 100644 --- a/Source/Makefile +++ b/Source/Makefile @@ -26,6 +26,7 @@ EL_FILES := \ Hull/FaceSet.cs \ Hull/RawMesh.cs \ Hull/Triangle.cs \ + InternalParentConstraint.cs \ Recipes/BuildCost.cs \ Recipes/BuildResource.cs \ Recipes/BuildResourceSet.cs \