Skip to content

Commit aa98056

Browse files
committed
comments & clarity
1 parent 7a4b4f3 commit aa98056

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

KSPCommunityFixes/BugFixes/ReRootPreserveSurfaceAttach.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ protected override void ApplyPatches(List<PatchInfo> patches)
3434
// it tries to alter a part's surface attachment so that it mirrors the surface attach node of its parent.
3535
// But that's not a great idea, because a lot of things depend on the surface attach node never changing.
3636
// For example, if the user then picks the part back up, it won't attach the same way to anything else
37-
// To Fix this, instead of using the child's actual srfAttachNode, we create a new surface attach node and
37+
// To fix this, instead of using the child's actual srfAttachNode we create a new surface attach node and
3838
// just stick it in the regular AttachNode list.
3939
static bool AttachNode_ReverseSrfNodeDirection_Prefix(AttachNode __instance, AttachNode fromNode)
4040
{
@@ -43,11 +43,17 @@ static bool AttachNode_ReverseSrfNodeDirection_Prefix(AttachNode __instance, Att
4343
AttachNode newSrfAttachNode = AttachNode.Clone(fromNode);
4444
newSrfAttachNode.owner = __instance.owner;
4545
newSrfAttachNode.attachedPart = fromNode.owner;
46+
// the name here isn't important, but if anyone is debugging an issue I'd like to make it clear where it came from.
47+
// 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
4648
newSrfAttachNode.id = "KSPCF-reroot-srfAttachNode";
49+
50+
// convert the position, orientation from the other part's local space into ours
4751
Vector3 positionWorld = fromNode.owner.transform.TransformPoint(fromNode.position);
4852
Vector3 orientationWorld = fromNode.owner.transform.TransformDirection(fromNode.orientation);
49-
newSrfAttachNode.position = newSrfAttachNode.originalPosition = newSrfAttachNode.owner.transform.InverseTransformPoint(positionWorld);
50-
newSrfAttachNode.orientation = newSrfAttachNode.originalOrientation = -newSrfAttachNode.owner.transform.InverseTransformDirection(orientationWorld);
53+
newSrfAttachNode.originalPosition = newSrfAttachNode.owner.transform.InverseTransformPoint(positionWorld);
54+
newSrfAttachNode.originalOrientation = -newSrfAttachNode.owner.transform.InverseTransformDirection(orientationWorld);
55+
newSrfAttachNode.position = newSrfAttachNode.originalPosition;
56+
newSrfAttachNode.orientation = newSrfAttachNode.originalOrientation;
5157
newSrfAttachNode.owner.attachNodes.Add(newSrfAttachNode);
5258

5359
// now clear the srfAttachNodes from both parts

0 commit comments

Comments
 (0)