Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Source/Modules/ModuleCoPFollowTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,43 @@
[KSPField]
public string transformName;

[SerializeField]
private Transform followTransform;

public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
if (HighLogic.LoadedScene != GameScenes.LOADING)
if (followTransform == null || followTransform.name != transformName)
{
if (transformName != null) followTransform = part.FindModelTransform(transformName);
if (followTransform == null) Debug.LogError($"[{MODULENAME}] transformName was empty or does not exist.");
if (followTransform == null) Debug.LogError($"[{MODULENAME}] transformName '{transformName}' was empty or does not exist on part '{part.partInfo?.name}'");
}

if (followTransform == null && part.partInfo != null)
{
// this may be important if someone is swapping out versions of this module with B9PS
// Note this probably isn't correct for parts that also have modules that mess with this field (e.g. ModuleProceduralFairing)
part.CoPOffset = part.partInfo.CoPOffset;

Check failure on line 33 in Source/Modules/ModuleCoPFollowTransform.cs

View workflow job for this annotation

GitHub Actions / build / build

'AvailablePart' does not contain a definition for 'CoPOffset' and no accessible extension method 'CoPOffset' accepting a first argument of type 'AvailablePart' could be found (are you missing a using directive or an assembly reference?)
}

// NOTE: isEnabled will be persisted to the save file, but we want to treat it purely as runtime state
this.isEnabled = followTransform != null;
this.enabled = followTransform != null && HighLogic.LoadedSceneIsFlight;
}

public void FixedUpdate()
{
if (followTransform != null) part.CoPOffset = part.transform.InverseTransformPoint(followTransform.position);
// Note that we shouldn't ever get here if the transform just didn't exist
// But it's certainly possible for *something* to delete it later
if (followTransform == null)
{
isEnabled = false;
enabled = false;
// should we reset CoPOffset here? Not sure.
}
else
{
part.CoPOffset = part.transform.InverseTransformPoint(followTransform.position);
}
}
}
}
Loading