public static SetPartLocalPosRotFrom ( Transform trf, Transform from, Vector3 localPos, Quaternion localRot ) : void | ||
trf | Transform | |
from | Transform | |
localPos | Vector3 | |
localRot | Quaternion | |
return | void |
private IEnumerator WaitPhysicUpdate() { yield return(new WaitForFixedUpdate()); KAS_Shared.SetPartLocalPosRotFrom(physicObj.transform, this.part.transform, currentLocalPos, currentLocalRot); if (physicObj.rigidbody.isKinematic == false) { KAS_Shared.DebugLog("WaitPhysicUpdate(PhysicChild) Set velocity to : " + this.part.rigidbody.velocity + " | angular velocity : " + this.part.rigidbody.angularVelocity); physicObj.rigidbody.angularVelocity = this.part.rigidbody.angularVelocity; physicObj.rigidbody.velocity = this.part.rigidbody.velocity; } }
/// <summary>Part's message handler.</summary> /// <remarks>Resumes physics handling on the object.</remarks> void OnPartUnpack() { if (physicObj != null && physicObjRb.isKinematic) { KAS_Shared.DebugLog("OnPartUnpack(PhysicChild)"); physicObj.transform.parent = null; KAS_Shared.SetPartLocalPosRotFrom( physicObj.transform, part.transform, currentLocalPos, currentLocalRot); physicObjRb.isKinematic = false; StartCoroutine(WaitAndUpdateVelocities()); } }
/// <summary>Aligns position, rotation and velocity of the rigidbody.</summary> /// <remarks>The update is delayed till the next fixed update to let game's physics to work. /// </remarks> /// <returns>Nothing.</returns> IEnumerator WaitAndUpdateVelocities() { yield return(new WaitForFixedUpdate()); KAS_Shared.SetPartLocalPosRotFrom( physicObj.transform, part.transform, currentLocalPos, currentLocalRot); if (!physicObjRb.isKinematic) { Debug.LogFormat("Set velocity to: {0} | angular velocity: {1}", part.Rigidbody.velocity, part.Rigidbody.angularVelocity); physicObjRb.angularVelocity = part.Rigidbody.angularVelocity; physicObjRb.velocity = part.Rigidbody.velocity; } }
public void OnPartUnpack() { if (physicActive) { if (physicObj.rigidbody.isKinematic) { KAS_Shared.DebugLog("OnPartUnpack(PhysicChild)"); physicObj.transform.parent = null; KAS_Shared.SetPartLocalPosRotFrom(physicObj.transform, this.part.transform, currentLocalPos, currentLocalRot); physicObj.rigidbody.isKinematic = false; FlightGlobals.addPhysicalObject(physicObj); StartCoroutine(WaitPhysicUpdate()); } } }
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; }