Skip to content

Commit

Permalink
comments & clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Feb 10, 2024
1 parent 7a4b4f3 commit aa98056
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions KSPCommunityFixes/BugFixes/ReRootPreserveSurfaceAttach.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void ApplyPatches(List<PatchInfo> patches)
// it tries to alter a part's surface attachment so that it mirrors the surface attach node of its parent.
// But that's not a great idea, because a lot of things depend on the surface attach node never changing.
// For example, if the user then picks the part back up, it won't attach the same way to anything else
// To Fix this, instead of using the child's actual srfAttachNode, we create a new surface attach node and
// To fix this, instead of using the child's actual srfAttachNode we create a new surface attach node and
// just stick it in the regular AttachNode list.
static bool AttachNode_ReverseSrfNodeDirection_Prefix(AttachNode __instance, AttachNode fromNode)
{
Expand All @@ -43,11 +43,17 @@ static bool AttachNode_ReverseSrfNodeDirection_Prefix(AttachNode __instance, Att
AttachNode newSrfAttachNode = AttachNode.Clone(fromNode);
newSrfAttachNode.owner = __instance.owner;
newSrfAttachNode.attachedPart = fromNode.owner;
// the name here isn't important, but if anyone is debugging an issue I'd like to make it clear where it came from.
// I'm pretty sure the empty string has some special meaning, and we need to be sure it doesn't collide with any existing node IDs
newSrfAttachNode.id = "KSPCF-reroot-srfAttachNode";

// convert the position, orientation from the other part's local space into ours
Vector3 positionWorld = fromNode.owner.transform.TransformPoint(fromNode.position);
Vector3 orientationWorld = fromNode.owner.transform.TransformDirection(fromNode.orientation);
newSrfAttachNode.position = newSrfAttachNode.originalPosition = newSrfAttachNode.owner.transform.InverseTransformPoint(positionWorld);
newSrfAttachNode.orientation = newSrfAttachNode.originalOrientation = -newSrfAttachNode.owner.transform.InverseTransformDirection(orientationWorld);
newSrfAttachNode.originalPosition = newSrfAttachNode.owner.transform.InverseTransformPoint(positionWorld);
newSrfAttachNode.originalOrientation = -newSrfAttachNode.owner.transform.InverseTransformDirection(orientationWorld);
newSrfAttachNode.position = newSrfAttachNode.originalPosition;
newSrfAttachNode.orientation = newSrfAttachNode.originalOrientation;
newSrfAttachNode.owner.attachNodes.Add(newSrfAttachNode);

// now clear the srfAttachNodes from both parts
Expand Down

0 comments on commit aa98056

Please sign in to comment.