Skip to content

Commit

Permalink
Fix child parts having their rotations broken -- we have to iterate f…
Browse files Browse the repository at this point in the history
…orwards over the parts list, not backwards, because if we iterate backwards then we'll be setting parent positions and rotations after child positions and rotations, which will cause child pos/rot to be recalculated. KSP keeps parts in hierarchy-order so iterating forwards is safe.
  • Loading branch information
NathanKell committed Nov 22, 2023
1 parent 3842fca commit aec5f3a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Source/VesselModuleRotationRO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,13 @@ public void SetPosRot(Quaternion rotation, Vector3 position)
return;
}

List<Part> parts = vessel.parts;
for (int i = parts.Count; i-- > 0;)
var parts = vessel.parts;
// Have to iterate forwards to preserve hierarchy
int c = parts.Count;
for (int i = 0; i < c; ++i)
{
Part part = parts[i];
part.transform.SetPositionAndRotation(position + rotation * part.orgPos, rotation * part.orgRot);
part.partTransform.SetPositionAndRotation(position + rotation * part.orgPos, rotation * part.orgRot);
}
}

Expand Down

0 comments on commit aec5f3a

Please sign in to comment.