Skip to content

Commit

Permalink
Add internal module to facilitate animated IVAs
Browse files Browse the repository at this point in the history
ie, when the sub-model that holds the IVA moves relative to the part.
It's just a simple parent-constraint that doesn't (yet?) support offset
position or rotation.
  • Loading branch information
taniwha committed Sep 6, 2020
1 parent 0a27abc commit 4cab2f4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Source/InternalParentConstraint.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
1 change: 1 addition & 0 deletions Source/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 4cab2f4

Please sign in to comment.