Skip to content

Commit

Permalink
Merge pull request #138 from ZiwKerman/develop
Browse files Browse the repository at this point in the history
Fix for the drift!
  • Loading branch information
ZiwKerman authored Dec 13, 2016
2 parents 1dd1ab1 + 733fcc0 commit 3f12964
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions InfernalRobotics/InfernalRobotics/Module/ModuleIRServo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ModuleIRServo : PartModule, IRescalable, IJointLockState
[KSPField(isPersistant = false)]
public float jointDamping = 0;

bool isOnRails = false;
bool isOnRails = true;

[KSPField(isPersistant = true)] public bool rotateLimits = false;
[KSPField(isPersistant = true)] public float rotateMax = 360;
Expand Down Expand Up @@ -192,7 +192,11 @@ public ModuleIRServo()
}

//BEGIN All KSPEvents&KSPActions

[KSPEvent (guiActive = true, guiActiveEditor = true, guiName = "Reattach FixedMesh", active = true)]
public void ReattachFixedMesh ()
{
AttachToParent ();
}
[KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "Engage Limits", active = false)]
public void LimitTweakableToggle()
{
Expand Down Expand Up @@ -436,6 +440,12 @@ public override void OnAwake()
Logger.Log(string.Format("[OnAwake] End, rotateLimits={0}, minTweak={1}, maxTweak={2}, rotateJoint={0}", rotateLimits, minTweak, maxTweak), Logger.Level.Debug);
}

public void onDestroy()
{
GameEvents.onVesselGoOnRails.Remove (OnVesselGoOnRails);
GameEvents.onVesselGoOffRails.Remove (OnVesselGoOffRails);
}

public void OnVesselGoOnRails (Vessel v)
{
if (v != vessel)
Expand Down Expand Up @@ -474,11 +484,14 @@ public void OnVesselGoOffRails (Vessel v)
return;

JointSetupDone = false;
Logger.Log ("[OnVesselGoOffRails] Resetting Joint", Logger.Level.Debug);

Logger.Log ("[OnVesselGoOffRails] Started for "+ part.name, Logger.Level.Debug);


if (joint)
{
DestroyImmediate (joint);
Logger.Log ("[OnVesselGoOffRails] Resetting Joint", Logger.Level.Debug);
DestroyImmediate (joint);
}

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

base.OnLoad (config);

//save persistent rotation/translation data, because the joint will be initialized at current position.
rotationDelta = rotation;
translationDelta = translation;

InitModule();

Logger.Log ("[OnLoad] Rebuilding Attachments", Logger.Level.Debug);
BuildAttachments ();

Logger.Log("[OnLoad] End", Logger.Level.Debug);
}
/// <summary>
Expand Down Expand Up @@ -618,19 +636,21 @@ protected void SetupMinMaxTweaks()
protected virtual void AttachToParent()
{
Transform fix = FixedMeshTransform;
//Transform fix = obj;

//first revert position to part position
fix.position = part.transform.position;
fix.rotation = part.transform.rotation;

if (rotateJoint)
{
fix.RotateAround(part.transform.TransformPoint(rotatePivot), part.transform.TransformDirection(rotateAxis),
//(invertSymmetry ? ((part.symmetryCounterparts.Count != 1) ? -1 : 1) : -1) *
-rotation);
-rotationDelta);
}
else if (translateJoint)
{
fix.Translate(part.transform.TransformDirection(translateAxis.normalized)*translation, Space.World);
fix.Translate(translateAxis.normalized*translationDelta, Space.Self);
}

fix.parent = part.parent.transform;
}
/// <summary>
Expand Down

0 comments on commit 3f12964

Please sign in to comment.