diff --git a/GameData/KSPCommunityFixes/Settings.cfg b/GameData/KSPCommunityFixes/Settings.cfg index 5930b88..5649f9e 100644 --- a/GameData/KSPCommunityFixes/Settings.cfg +++ b/GameData/KSPCommunityFixes/Settings.cfg @@ -240,6 +240,11 @@ KSP_COMMUNITY_FIXES // Fix the Alt+F12 console input field stealing input when a console entry is added DebugConsoleDontStealInput = true + // Fix the hard-coded lower limit for the moment of inertia of wheels being too large (0.01 t*m^2) and + // causing incorrectly large forces on small aircraft during touchdown. This fix should prevent your craft from + // pitching up or down unexpectedly when touching down. + WheelInertiaLimit = true + // ########################## // Obsolete bugfixes // ########################## diff --git a/KSPCommunityFixes/BugFixes/WheelInertiaLimit.cs b/KSPCommunityFixes/BugFixes/WheelInertiaLimit.cs new file mode 100644 index 0000000..0afa5b3 --- /dev/null +++ b/KSPCommunityFixes/BugFixes/WheelInertiaLimit.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using HarmonyLib; +using VehiclePhysics; +using UnityEngine; + +namespace KSPCommunityFixes +{ + public class WheelInertiaLimit : BasePatch + { + protected override Version VersionMin => new Version(1, 12, 0); + + protected override void ApplyPatches() + { + AddPatch(PatchType.Postfix, typeof(VehiclePhysics.Wheel), nameof(VehiclePhysics.Wheel.RecalculateConstants)); + } + + static void Wheel_RecalculateConstants_Postfix(VehiclePhysics.Wheel __instance) + { + __instance.I = __instance.mass * __instance.radius * __instance.radius * 0.5f; + + if (__instance.I < 0.00001f) + { + __instance.I = 0.00001f; + } + + __instance.invI = 1f / __instance.I; + } + } +} diff --git a/KSPCommunityFixes/KSPCommunityFixes.csproj b/KSPCommunityFixes/KSPCommunityFixes.csproj index 5b2be6c..64790a5 100644 --- a/KSPCommunityFixes/KSPCommunityFixes.csproj +++ b/KSPCommunityFixes/KSPCommunityFixes.csproj @@ -128,6 +128,7 @@ +