public override void OnSave(ConfigNode node) { base.OnSave(node); foreach (KeyValuePair <int, SectionInfo> section in sections) { ConfigNode sectionNode = node.AddNode("SECTIONPOS"); sectionNode.AddValue("index", section.Key); sectionNode.AddValue("localPos", KSPUtil.WriteVector(KAS_Shared.GetLocalPosFrom(section.Value.transform, this.part.transform))); sectionNode.AddValue("localRot", KSPUtil.WriteQuaternion(KAS_Shared.GetLocalRotFrom(section.Value.transform, this.part.transform))); } }
/// <summary>Part's message handler.</summary> /// <remarks>Temporarily suspends physics handling on the object.</remarks> void OnPartPack() { if (physicObj != null) { KAS_Shared.DebugLog("OnPartPack(PhysicChild)"); currentLocalPos = KAS_Shared.GetLocalPosFrom(physicObj.transform, part.transform); currentLocalRot = KAS_Shared.GetLocalRotFrom(physicObj.transform, part.transform); physicObjRb.isKinematic = true; physicObj.transform.parent = part.transform; StartCoroutine(WaitAndUpdateVelocities()); } }
public void OnPartPack() { if (physicActive) { KAS_Shared.DebugLog("OnPartPack(PhysicChild)"); currentLocalPos = KAS_Shared.GetLocalPosFrom(physicObj.transform, this.part.transform); currentLocalRot = KAS_Shared.GetLocalRotFrom(physicObj.transform, this.part.transform); FlightGlobals.removePhysicalObject(physicObj); physicObj.rigidbody.isKinematic = true; physicObj.transform.parent = this.part.transform; StartCoroutine(WaitPhysicUpdate()); } }
private void UpdateRotorPos() { if (!hingeJnt) { return; } currentAngle = hingeJnt.angle; currentSpeed = rotorTransform.rigidbody.angularVelocity.magnitude; rotorLocalPos = KAS_Shared.GetLocalPosFrom(rotorTransform.transform, this.part.transform); rotorLocalRot = KAS_Shared.GetLocalRotFrom(rotorTransform.transform, this.part.transform); if (rotorGoingTo) { float angleDif = Math.Abs(hingeJnt.spring.targetPosition - currentAngle); if (angleDif < goToMinAngle && currentSpeed < goToMinSpeed) { MotorStop(); } } }
private void LoadSections() { sections.Clear(); sectionTotalLenght = 0; ConfigNode node = KAS_Shared.GetBaseConfigNode(this); int i = 0; foreach (ConfigNode sectionNode in node.GetNodes("SECTION")) { if (sectionNode.HasValue("transformName") && sectionNode.HasValue("lenght")) { SectionInfo section = new SectionInfo(); string sectionTransformName = sectionNode.GetValue("transformName"); section.transform = this.part.FindModelTransform(sectionTransformName); if (!section.transform) { KAS_Shared.DebugError("LoadSections(TelescopicArm) Section transform " + sectionTransformName + " not found in the model !"); continue; } if (!float.TryParse(sectionNode.GetValue("lenght"), out section.lenght)) { KAS_Shared.DebugError( "LoadSections(TelescopicArm) Unable to parse lenght of the Section : " + sectionTransformName); continue; } section.orgLocalPos = KAS_Shared.GetLocalPosFrom(section.transform, this.part.transform); section.orgLocalRot = KAS_Shared.GetLocalRotFrom(section.transform, this.part.transform); if (savedSectionsLocalPos.Count > 0) { section.savedLocalPos = savedSectionsLocalPos[i]; } sections.Add(i, section); sectionTotalLenght += section.lenght; i++; } } }
public void LoadRotor() { KAS_Shared.DebugLog("LoadRotor(Rotor) - Find rotor transform..."); rotorTransform = this.part.FindModelTransform(rotorTransformName); KAS_Shared.DebugLog("LoadRotor(Rotor) - Create physical object..."); rotorPhysicModule = this.part.gameObject.GetComponent <KASModulePhysicChild>(); if (!rotorPhysicModule) { KAS_Shared.DebugLog("LoadRotor(Rotor) - KASModulePhysicChild do not exist, adding it..."); rotorPhysicModule = this.part.gameObject.AddComponent <KASModulePhysicChild>(); } rotorPhysicModule.mass = rotorMass; rotorPhysicModule.physicObj = rotorTransform.gameObject; rotorPhysicModule.Start(); orgRotorMass = this.part.mass; float newMass = this.part.mass - rotorMass; if (newMass > 0) { this.part.mass = newMass; } else { KAS_Shared.DebugWarning("LoadRotor(Rotor) - Mass of the rotor is greater than the part !"); } KAS_Shared.DebugLog("LoadRotor - Save original rotor position..."); rotorOrgLocalPos = KAS_Shared.GetLocalPosFrom(rotorTransform, this.part.transform); rotorOrgLocalRot = KAS_Shared.GetLocalRotFrom(rotorTransform, this.part.transform); KAS_Shared.DebugLog("LoadRotor - Disable collision..."); if (rotorTransform.collider) { KAS_Shared.DisableVesselCollision(this.part.vessel, rotorTransform.collider); } else { KAS_Shared.DebugError("LoadRotor - Rotor transform do not have any collider !"); } KAS_Shared.DebugLog("LoadRotor - Create hinge joint..."); hingeJnt = this.part.gameObject.AddComponent <HingeJoint>(); hingeJnt.connectedBody = rotorTransform.rigidbody; ResetLimitsConfig(); ResetMotorConfig(); ResetSpringConfig(); ResetJointConfig(); if (firstLoad) { firstLoad = false; } else { KAS_Shared.DebugLog("LoadRotor - Return rotor to the current position and rotation : " + rotorLocalPos + " | " + rotorLocalRot); KAS_Shared.SetPartLocalPosRotFrom(rotorTransform.transform, this.part.transform, rotorLocalPos, rotorLocalRot); } // Get rotor attach nodes attachNodes.Clear(); ConfigNode node = KAS_Shared.GetBaseConfigNode(this); List <string> attachNodesSt = new List <string>(node.GetValues("attachNode")); foreach (String anString in attachNodesSt) { AttachNode an = this.part.findAttachNode(anString); if (an != null) { KAS_Shared.DebugLog("LoadRotor - Rotor attach node added : " + an.id); attachNodes.Add(an); if (an.attachedPart) { KAS_Shared.DebugLog("LoadRotor - Setting rotor joint on : " + an.attachedPart.partInfo.title); KAS_Shared.RemoveFixedJointBetween(this.part, an.attachedPart); KAS_Shared.RemoveHingeJointBetween(this.part, an.attachedPart); FixedJoint fjnt = an.attachedPart.gameObject.AddComponent <FixedJoint>(); fjnt.connectedBody = rotorTransform.rigidbody; fixedJnts.Add(fjnt); } } } MotorStop(); rotorLoaded = true; }