Skip to content

Commit d2d97e9

Browse files
committed
Version 0.1
- Added ModuleCoPFollowTransform
1 parent f78e9ca commit d2d97e9

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ Compatible with **KSP 1.12.3** and up - Available on [CKAN]
1919

2020
### Included part modules
2121

22+
- **ModuleCoPFollowTransform**<br/>This module adjusts the Centre of Pressure (CoP) to follow a specified transform on the same part, improving functionality for animated drag-based systems like parachutes.
23+
24+
2225
[CKAN]: https://forum.kerbalspaceprogram.com/topic/197082-ckan-the-comprehensive-kerbal-archive-network-v1332-laplace-ksp-2-support/

Source/KSPCommunityPartModules.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
<PackageReference Include="KSPBuildTools" Version="0.0.2-alpha.5" />
3535
</ItemGroup>
3636
<ItemGroup>
37+
<Compile Include="Modules\ModuleCoPFollowTransform.cs" />
3738
<Compile Include="Properties\AssemblyInfo.cs" />
3839
</ItemGroup>
3940
<ItemGroup>
4041
<Content Include="HOW_TO_BUILD.txt" />
4142
</ItemGroup>
42-
<ItemGroup/>
43+
<ItemGroup />
4344
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
4445
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Usecase: Making the Centre of Pressure follow a transform on the same part.
3+
Example: BoringCrewServices Starliner main parachutes
4+
Originally By: Sofie Brink
5+
Originally For: KSPCommunityPartModules
6+
*/
7+
using UnityEngine;
8+
9+
namespace KSPCommunityPartModules.Modules
10+
{
11+
public class ModuleCoPFollowTransform : PartModule
12+
{
13+
public const string MODULENAME = nameof(ModuleCoPFollowTransform);
14+
15+
[KSPField]
16+
public string transformName;
17+
18+
private Transform followTransform;
19+
20+
public override void OnLoad(ConfigNode node)
21+
{
22+
base.OnLoad(node);
23+
if (HighLogic.LoadedScene != GameScenes.LOADING)
24+
{
25+
if (transformName != null) followTransform = part.FindModelTransform(transformName);
26+
if (followTransform == null) Debug.LogError($"[{MODULENAME}] transformName was empty or does not exist.");
27+
}
28+
}
29+
30+
public void FixedUpdate()
31+
{
32+
if (followTransform != null) part.CoPOffset = part.transform.InverseTransformPoint(followTransform.position);
33+
}
34+
}
35+
}

Source/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737

3838
[assembly: KSPAssembly(name: "KSPCommunityPartModules"
3939
, versionMajor: 0
40-
, versionMinor: 0
41-
, versionRevision: 1)]
40+
, versionMinor: 1
41+
, versionRevision: 0)]

0 commit comments

Comments
 (0)