From f41b57a97e1f760354afd03d03570ba58b2fa6eb Mon Sep 17 00:00:00 2001 From: xen-42 Date: Wed, 9 Oct 2024 21:45:45 -0400 Subject: [PATCH] Fix moving satellites of satellites --- NewHorizons/Handlers/PlanetCreationHandler.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 201def01..f0001677 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -848,6 +848,8 @@ namespace NewHorizons.Handlers // Get ready to move all the satellites var relativeMoonPositions = children.Select(x => x.transform.position - go.transform.position).ToArray(); + var relativeMoonMoonPositions = children.Select(x => AstroObjectLocator.GetChildren(x.GetComponent()) + .Select(childchild => (childchild?.transform?.position ?? Vector3.zero) - go.transform.position)).ToArray(); // If its tidally locked change the alignment var alignment = go.GetComponent(); @@ -874,11 +876,15 @@ namespace NewHorizons.Handlers } else { + var j = 0; foreach (var childChild in AstroObjectLocator.GetChildren(childAO)) { - if (childChild == null) continue; - var dPos = childChild.transform.position - child.transform.position; - childChild.transform.position = go.transform.position + relativeMoonPositions[i] + dPos; + if (childChild != null) + { + var dPos = relativeMoonMoonPositions[i].ElementAt(j); + childChild.transform.position = go.transform.position + dPos; + } + j++; } // Make sure the moons get updated to the new AO childAO._primaryBody = newAO;