Skip to content

Commit fbbe476

Browse files
MajorNr01Phantomical
authored andcommitted
Fix lower limit for wheel moment of inertia (#341)
When the game calculates the moment of inertia for wheels, it sets a hard-coded lower limit of `0.01`. This is much larger than the calculated moment of inertia of most landing gear wheels (e.g. the LY-10 Small Landing Gear has a moment of inertia of `0.000648`). This causes significant forces on small aircraft (~10t) during touchdown as the wheels spin up. As a result, the craft pitches down if the wheels are not spinning and pitches up if the wheels are still spinning. This is correct in principle but very exaggerated in small aircraft due to the inappropriately large moment of inertia. This patch changes the lower limit to `0.00001` which is lower than the correct moment of inertia of the stock landing gears. The chosen lower limit is kind of arbitrary (I just added three zeroes) and I am completely open to lowering it even further or removing it entirely.
1 parent 2c64c3a commit fbbe476

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

GameData/KSPCommunityFixes/Settings.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ KSP_COMMUNITY_FIXES
240240
// Fix the Alt+F12 console input field stealing input when a console entry is added
241241
DebugConsoleDontStealInput = true
242242
243+
// Fix the hard-coded lower limit for the moment of inertia of wheels being too large (0.01 t*m^2) and
244+
// causing incorrectly large forces on small aircraft during touchdown. This fix should prevent your craft from
245+
// pitching up or down unexpectedly when touching down.
246+
WheelInertiaLimit = true
247+
243248
// ##########################
244249
// Obsolete bugfixes
245250
// ##########################
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using HarmonyLib;
4+
using VehiclePhysics;
5+
using UnityEngine;
6+
7+
namespace KSPCommunityFixes
8+
{
9+
public class WheelInertiaLimit : BasePatch
10+
{
11+
protected override Version VersionMin => new Version(1, 12, 0);
12+
13+
protected override void ApplyPatches()
14+
{
15+
AddPatch(PatchType.Postfix, typeof(VehiclePhysics.Wheel), nameof(VehiclePhysics.Wheel.RecalculateConstants));
16+
}
17+
18+
static void Wheel_RecalculateConstants_Postfix(VehiclePhysics.Wheel __instance)
19+
{
20+
__instance.I = __instance.mass * __instance.radius * __instance.radius * 0.5f;
21+
22+
if (__instance.I < 0.00001f)
23+
{
24+
__instance.I = 0.00001f;
25+
}
26+
27+
__instance.invI = 1f / __instance.I;
28+
}
29+
}
30+
}

KSPCommunityFixes/KSPCommunityFixes.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<Compile Include="BugFixes\ChutePhantomSymmetry.cs" />
134134
<Compile Include="BugFixes\CorrectDragForFlags.cs" />
135135
<Compile Include="BugFixes\DebugConsoleDontStealInput.cs" />
136+
<Compile Include="BugFixes\WheelInertiaLimit.cs" />
136137
<Compile Include="BugFixes\DragCubeLoadException.cs" />
137138
<Compile Include="BugFixes\EVAConstructionMass.cs" />
138139
<Compile Include="BugFixes\FastAndFixedEnumExtensions.cs" />

0 commit comments

Comments
 (0)