Skip to content

Commit 86a37ad

Browse files
committed
V1.1 : Added parallel / antiparallel modes
1 parent 485a4f8 commit 86a37ad

10 files changed

Lines changed: 267 additions & 177 deletions

FlyByWireSASMode.cs

Lines changed: 161 additions & 99 deletions
Large diffs are not rendered by default.

FlyByWireSASMode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<ItemGroup>
8787
<Compile Include="FlyByWireSASMode.cs" />
8888
<Compile Include="Properties\AssemblyInfo.cs" />
89-
<Compile Include="VesselFlyByWireState.cs" />
89+
<Compile Include="VesselState.cs" />
9090
</ItemGroup>
9191
<ItemGroup>
9292
<None Include="packages.config" />

GameData/FlyByWireSASMode/FlyByWireSASMode.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"NAME": "FlyByWireSASMode",
33
"URL": "https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/GameData/FlyByWireSASMode/FlyByWireSASMode.version",
44
"DOWNLOAD": "https://github.com/gotmachine/FlyByWireSASMode/releases",
5-
"VERSION": {"MAJOR": 1, "MINOR": 0, "PATCH": 0, "BUILD": 0},
5+
"VERSION": {"MAJOR": 1, "MINOR": 1, "PATCH": 0, "BUILD": 0},
66
"KSP_VERSION": {"MAJOR": 1, "MINOR": 12, "PATCH": 5},
77
"KSP_VERSION_MIN": {"MAJOR": 1, "MINOR": 12, "PATCH": 3},
88
"KSP_VERSION_MAX": {"MAJOR": 1, "MINOR": 12, "PATCH": 5}
584 Bytes
Loading
600 Bytes
Loading

NavballScreenshot.png

1.97 KB
Loading

Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Reflection;
1+
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

@@ -33,4 +33,4 @@
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.1.0.0")]

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ This Kerbal Space Program plugin adds a new **fly by wire** SAS mode.
44

55
When enabled, pitch and yaw inputs don't control the vessel directly anymore, but instead control the position of a custom navball direction marker that the SAS will follow automatically.
66

7+
Additionally, this also add two target related modes, **parallel** and **antiparallel**, especially useful for docking.
8+
79
![Navball](https://raw.githubusercontent.com/gotmachine/FlyByWireSASMode/master/NavballScreenshot.png)
810

911

10-
The **fly by wire** mode is available for pilots and probe cores at the same SAS level as the target and maneuver modes, but this is configurable in the ```settings.cfg``` file.
12+
These addtional modes are available for pilots and probe cores at the same SAS level as the target and maneuver modes, but this is configurable in the ```settings.cfg``` file (doing that with a ModuleManager patch is recommended).
1113

1214
### Download and installation
1315

@@ -27,5 +29,8 @@ MIT
2729

2830
### Changelog
2931

32+
#### 1.1.0 - 28/04/2024
33+
- Added parallel / antiparallel modes
34+
3035
#### 1.0.0 - 27/04/2024
3136
- Inital release

VesselFlyByWireState.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.

VesselState.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using UnityEngine;
2+
3+
namespace FlyByWireSASMode
4+
{
5+
internal enum CustomSASMode
6+
{
7+
Stock,
8+
FlyByWire,
9+
ParallelPos,
10+
ParallelNeg
11+
}
12+
13+
internal class VesselState
14+
{
15+
public Vessel vessel;
16+
public CustomSASMode sasMode;
17+
public Vector3 direction;
18+
19+
public VesselState(Vessel vessel, CustomSASMode sasMode)
20+
{
21+
this.vessel = vessel;
22+
this.sasMode = sasMode;
23+
vessel.OnPreAutopilotUpdate += OnPreAutopilotUpdate;
24+
ResetDirection();
25+
}
26+
27+
public void ResetDirection()
28+
{
29+
direction = vessel.GetTransform().up;
30+
}
31+
32+
public void Destroy()
33+
{
34+
vessel.OnPreAutopilotUpdate -= OnPreAutopilotUpdate;
35+
}
36+
37+
private void OnPreAutopilotUpdate(FlightCtrlState st)
38+
{
39+
// continuously set mode to stability assist so we know which button to disable
40+
vessel.Autopilot.mode = VesselAutopilot.AutopilotMode.StabilityAssist;
41+
42+
if (sasMode == CustomSASMode.FlyByWire)
43+
{
44+
// clear manual input
45+
st.pitch = 0f;
46+
st.yaw = 0f;
47+
48+
if (FlightGlobals.ActiveVessel == vessel)
49+
{
50+
// get input manually so this can work when under partial control
51+
float pitch, yaw;
52+
if (GameSettings.PITCH_DOWN.GetKey())
53+
pitch = -1f;
54+
else if (GameSettings.PITCH_UP.GetKey())
55+
pitch = 1f;
56+
else
57+
pitch = 0f;
58+
59+
if (GameSettings.YAW_LEFT.GetKey())
60+
yaw = -1f;
61+
else if (GameSettings.YAW_RIGHT.GetKey())
62+
yaw = 1f;
63+
else
64+
yaw = 0f;
65+
66+
// increase speed when further away from control direction
67+
float speed = Vector3.Dot(vessel.GetTransform().up, direction) - 1.2f;
68+
69+
// transform pitch/yaw input into a X/Y translation on the navball
70+
Quaternion navballAttitudeGymbal = FlyByWireSASMode.instance.navBall.attitudeGymbal;
71+
direction =
72+
navballAttitudeGymbal.Inverse()
73+
* Quaternion.Euler(pitch * -speed, yaw * -speed, 0f)
74+
* navballAttitudeGymbal
75+
* direction;
76+
77+
direction.Normalize();
78+
}
79+
}
80+
else
81+
{
82+
Transform targetTransform = vessel.targetObject?.GetTransform();
83+
if (targetTransform == null)
84+
return;
85+
86+
direction = vessel.targetObject is Vessel ? targetTransform.up : vessel.targetObject.GetFwdVector();
87+
if (sasMode == CustomSASMode.ParallelNeg)
88+
direction *= -1f;
89+
}
90+
91+
// set SAS to follow requested direction
92+
vessel.Autopilot.SAS.lockedMode = false;
93+
vessel.Autopilot.SAS.SetTargetOrientation(direction, false);
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)