Skip to content

Commit

Permalink
Pre-rotate the anchor transform
Browse files Browse the repository at this point in the history
This is the launch clamp side of the fix for the EL-ReStock launch clamp
compatibility issue. The issue was reported in the EL thread and started
out as issues with getting the build cost but after fixing that, had
issues with the clamps extending properly when built at a survey site.
The bulk of the fix for that is (or will be) in EL, but this change is
for handling rotated clamps: it points the tower in the correct (editor)
direction prior to the tower being extended.
  • Loading branch information
taniwha committed Sep 13, 2020
1 parent a9bdd45 commit 7a29651
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Source/Restock/ModuleRestockLaunchClamp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ModuleRestockLaunchClamp : LaunchClamp
public LaunchClampGirderFactory girderFactory;

private int _girderSegments;
private Quaternion towerRot;

private Material _girderMaterial;
private Matrix4x4[] _girderMatrices;
Expand Down Expand Up @@ -63,12 +64,28 @@ public override void OnLoad(ConfigNode node)
girderFactory.Initialize(girderMesh, girderSegmentHeight, maxSegments);
}
}

if (node.HasValue ("towerRot"))
{
string rot = node.GetValue ("towerRot");
towerRot = KSPUtil.ParseQuaternion (rot);
}

_girderSegments = 1;

base.OnLoad(node);
}

public void RotateTower ()
{
// transforms found in OnLoad
float height = Vector3.Distance (towerAnchor.position, towerStretch.position);
//Debug.Log($"[ModuleRestockLaunchClamp] RotateTower: {height} {towerRot}");
towerPivot.localRotation = towerRot;
towerAnchor.localRotation = towerRot;
towerAnchor.position = towerStretch.position - towerStretch.up * height;
}

public override void OnStart(StartState state)
{
base.OnStart(state);
Expand Down Expand Up @@ -144,4 +161,4 @@ private void UpdateGirderMesh(int girderSegments)
girderMeshFilter.mesh = girderFactory.makeGirder(girderSegments);
}
}
}
}

0 comments on commit 7a29651

Please sign in to comment.