diff --git a/MechJeb2/MechJebLib/Maths/Functions.cs b/MechJeb2/MechJebLib/Maths/Functions.cs
index 0367461f4..559421b09 100644
--- a/MechJeb2/MechJebLib/Maths/Functions.cs
+++ b/MechJeb2/MechJebLib/Maths/Functions.cs
@@ -23,13 +23,11 @@ public static class Functions
/// Celestial longitude of the current position of the launch site.
/// Longitude of the Ascending Node of the target plane (degrees).
/// Inclination of the target plane (degrees).
- /// True when the returned time is until the northern launch window, false for the southern window.
- public static double MinimumTimeToPlane(double rotationPeriod,double latitude,double celestialLongitude,double LAN,double inc, out bool launchNorth)
+ public static (double time, double inclination) MinimumTimeToPlane(double rotationPeriod,double latitude,double celestialLongitude,double LAN,double inc)
{
double north = TimeToPlane(rotationPeriod,latitude,celestialLongitude,LAN,Math.Abs(inc));
double south = TimeToPlane(rotationPeriod,latitude,celestialLongitude,LAN,-Math.Abs(inc));
- launchNorth = (north < south);
- return Math.Min(north, south);
+ return north < south ? (north,Math.Abs(inc)) : (south,-Math.Abs(inc));
}
diff --git a/MechJeb2/MechJebModuleAscentGuidance.cs b/MechJeb2/MechJebModuleAscentGuidance.cs
index 4437202ce..8a38f4b70 100644
--- a/MechJeb2/MechJebModuleAscentGuidance.cs
+++ b/MechJeb2/MechJebModuleAscentGuidance.cs
@@ -441,18 +441,15 @@ private void ShowAutoWarpGUIElements()
if (targetExists && GuiUtils.ButtonTextBox(CachedLocalizer.Instance.MechJeb_Ascent_button15,autopilot.launchLANDifference,"ยบ",width: LAN_width)) //Launch into plane of target
{
launchingToPlane = true;
- autopilot.StartCountdown(vesselState.time +
- Functions.MinimumTimeToPlane(
- mainBody.rotationPeriod,
- vesselState.latitude,
- vesselState.celestialLongitude,
- core.target.TargetOrbit.LAN - autopilot.launchLANDifference,
- core.target.TargetOrbit.inclination,
- out bool launchingNorth
- )
- );
- // Fix up the sign of the inclination to match the window MinimumTimeToPlane selected
- desiredInclination = launchingNorth ? Math.Abs(desiredInclination) : -Math.Abs(desiredInclination);
+ (double timeToPlane, double inclination) = Functions.MinimumTimeToPlane(
+ mainBody.rotationPeriod,
+ vesselState.latitude,
+ vesselState.celestialLongitude,
+ core.target.TargetOrbit.LAN - autopilot.launchLANDifference,
+ core.target.TargetOrbit.inclination
+ );
+ autopilot.StartCountdown(vesselState.time + timeToPlane);
+ desiredInclination = inclination;
}
//Launch to target LAN
@@ -494,13 +491,6 @@ out bool launchingNorth
if (Launching)
{
- if (launchingToPlane)
- {
- desiredInclination = MuUtils.Clamp(core.target.TargetOrbit.inclination,Math.Abs(vesselState.latitude),180 - Math.Abs(vesselState.latitude));
- desiredInclination *=
- Math.Sign(Vector3d.Dot(core.target.TargetOrbit.SwappedOrbitNormal(),
- Vector3d.Cross(vesselState.CoM - mainBody.position,mainBody.transform.up)));
- }
GUILayout.Label(launchTimer);
if (GUILayout.Button(CachedLocalizer.Instance.MechJeb_Ascent_button17))//Abort
launchingToPlane = launchingToRendezvous = launchingToMatchLAN = launchingToLAN = autopilot.timedLaunch = false;