Skip to content

Commit 3f12964

Browse files
authored
Merge pull request #138 from ZiwKerman/develop
Fix for the drift!
2 parents 1dd1ab1 + 733fcc0 commit 3f12964

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ModuleIRServo : PartModule, IRescalable, IJointLockState
5757
[KSPField(isPersistant = false)]
5858
public float jointDamping = 0;
5959

60-
bool isOnRails = false;
60+
bool isOnRails = true;
6161

6262
[KSPField(isPersistant = true)] public bool rotateLimits = false;
6363
[KSPField(isPersistant = true)] public float rotateMax = 360;
@@ -192,7 +192,11 @@ public ModuleIRServo()
192192
}
193193

194194
//BEGIN All KSPEvents&KSPActions
195-
195+
[KSPEvent (guiActive = true, guiActiveEditor = true, guiName = "Reattach FixedMesh", active = true)]
196+
public void ReattachFixedMesh ()
197+
{
198+
AttachToParent ();
199+
}
196200
[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "Engage Limits", active = false)]
197201
public void LimitTweakableToggle()
198202
{
@@ -436,6 +440,12 @@ public override void OnAwake()
436440
Logger.Log(string.Format("[OnAwake] End, rotateLimits={0}, minTweak={1}, maxTweak={2}, rotateJoint={0}", rotateLimits, minTweak, maxTweak), Logger.Level.Debug);
437441
}
438442

443+
public void onDestroy()
444+
{
445+
GameEvents.onVesselGoOnRails.Remove (OnVesselGoOnRails);
446+
GameEvents.onVesselGoOffRails.Remove (OnVesselGoOffRails);
447+
}
448+
439449
public void OnVesselGoOnRails (Vessel v)
440450
{
441451
if (v != vessel)
@@ -474,11 +484,14 @@ public void OnVesselGoOffRails (Vessel v)
474484
return;
475485

476486
JointSetupDone = false;
477-
Logger.Log ("[OnVesselGoOffRails] Resetting Joint", Logger.Level.Debug);
487+
488+
Logger.Log ("[OnVesselGoOffRails] Started for "+ part.name, Logger.Level.Debug);
489+
478490

479491
if (joint)
480492
{
481-
DestroyImmediate (joint);
493+
Logger.Log ("[OnVesselGoOffRails] Resetting Joint", Logger.Level.Debug);
494+
DestroyImmediate (joint);
482495
}
483496

484497
SetupJoints ();
@@ -548,12 +561,17 @@ public override void OnLoad(ConfigNode config)
548561
{
549562
Logger.Log("[OnLoad] Start", Logger.Level.Debug);
550563

564+
base.OnLoad (config);
565+
551566
//save persistent rotation/translation data, because the joint will be initialized at current position.
552567
rotationDelta = rotation;
553568
translationDelta = translation;
554569

555570
InitModule();
556571

572+
Logger.Log ("[OnLoad] Rebuilding Attachments", Logger.Level.Debug);
573+
BuildAttachments ();
574+
557575
Logger.Log("[OnLoad] End", Logger.Level.Debug);
558576
}
559577
/// <summary>
@@ -618,19 +636,21 @@ protected void SetupMinMaxTweaks()
618636
protected virtual void AttachToParent()
619637
{
620638
Transform fix = FixedMeshTransform;
621-
//Transform fix = obj;
622-
639+
//first revert position to part position
640+
fix.position = part.transform.position;
641+
fix.rotation = part.transform.rotation;
623642

624643
if (rotateJoint)
625644
{
626645
fix.RotateAround(part.transform.TransformPoint(rotatePivot), part.transform.TransformDirection(rotateAxis),
627646
//(invertSymmetry ? ((part.symmetryCounterparts.Count != 1) ? -1 : 1) : -1) *
628-
-rotation);
647+
-rotationDelta);
629648
}
630649
else if (translateJoint)
631650
{
632-
fix.Translate(part.transform.TransformDirection(translateAxis.normalized)*translation, Space.World);
651+
fix.Translate(translateAxis.normalized*translationDelta, Space.Self);
633652
}
653+
634654
fix.parent = part.parent.transform;
635655
}
636656
/// <summary>

0 commit comments

Comments
 (0)