/// <summary>Starts physics handling on the object.</summary> /// <remarks>The object is expected to not have rigidbody. The one will be added with the proper /// mass and velocity settings. Parent transform of the physics object will be set top /// <c>null</c>, and it will become an idependent object.</remarks> /// <param name="physicObj">Game object to attach physics to. In normal case it's never a part's /// gameobject.</param> /// <param name="mass">Mass of the rigidbody.</param> /// <param name="delayPhysics">If default or <c>false</c> then new object gets parent's velocity /// immediately. Otherwise, the rigidbody is created as kinematic and velocity is sync'ed in the /// next <c>FixedUpdate()</c> call.</param> public void StartPhysics(GameObject physicObj, float mass, bool delayPhysics = false) { KAS_Shared.DebugLog("StartPhysics(PhysicChild)"); if (this.physicObj == null) { this.physicObj = physicObj; physicObjRb = physicObj.AddComponent <Rigidbody>(); physicObjRb.mass = mass; physicObjRb.useGravity = false; if (delayPhysics) { physicObjRb.isKinematic = true; StartCoroutine(WaitAndPromoteToPhysic()); } else { physicObjRb.velocity = part.Rigidbody.velocity; physicObjRb.angularVelocity = part.Rigidbody.angularVelocity; physicObj.transform.parent = null; } } else { KAS_Shared.DebugWarning("StartPhysics(PhysicChild) Physic already started! Ignore."); } }
protected override void OnJointBreak(float breakForce) { base.OnJointBreak(breakForce); KAS_Shared.DebugWarning("A joint broken on " + part.partInfo.title + " !, force: " + breakForce); KAS_Shared.DebugWarning("Disable magnet..."); MagnetActive = false; }
public static Part GetPartByID(string vesselID, string partID) { Vessel searchVessel = FlightGlobals.Vessels.Find(ves => ves.id.ToString() == vesselID); if (searchVessel) { if (!searchVessel.loaded) { KAS_Shared.DebugWarning("GetPartByID - Searched vessel are not loaded, loading it..."); searchVessel.Load(); } Part searchedPart = searchVessel.Parts.Find(p => p.flightID.ToString() == partID); if (searchedPart) { return(searchedPart); } else { KAS_Shared.DebugError("GetPartByID - Searched part not found !"); } } else { KAS_Shared.DebugError("GetPartByID - Searched vessel not found !"); } return(null); }
public override void OnJointBreakFixed() { KAS_Shared.DebugWarning("OnJointBreak(Strut) A joint broken on " + part.partInfo.title + " !, force: " + breakForce); Unlink(); fxSndBroke.audio.Play(); }
public void AttachFixed(Part srcPart, Part tgtPart, float breakForce) { attachMode.FixedJoint = true; FixedAttach.srcPart = srcPart; FixedAttach.tgtPart = tgtPart; if (!srcPart.packed && !tgtPart.packed) { KAS_Shared.DebugLog("AttachFixed(Core) Create fixed joint on " + srcPart.partInfo.title + " with " + tgtPart.partInfo.title); if (FixedAttach.fixedJoint) { Destroy(FixedAttach.fixedJoint); } FixedAttach.fixedJoint = srcPart.gameObject.AddComponent <FixedJoint>(); FixedAttach.fixedJoint.connectedBody = tgtPart.rb; FixedAttach.fixedJoint.breakForce = breakForce; FixedAttach.fixedJoint.breakTorque = breakForce; } else { SetCreateJointOnUnpack(true); KAS_Shared.DebugWarning("AttachFixed(Core) Cannot create fixed joint as part(s) is packed," + " delaying to unpack..."); } }
void OnVesselWasModified(Vessel vesselModified) { if (vesselModified != this.vessel) { return; } if (linked) { if (linkedStrutModule.vessel != this.vessel) { if (allowDock) { KAS_Shared.DebugWarning("OnVesselWasModified(strut) Source and target vessel are" + " different, postponing docking strut... (allowDock = true)"); // This callback is invoked while the vessel is being // modified, so any further changes must be postponed. StartCoroutine(WaitAndRedock()); } else { KAS_Shared.DebugWarning("OnVesselWasModified(strut) Source and target vessel are" + " different, unlinking strut... (allowDock = false)"); Unlink(); fxSndBroke.audio.Play(); } } else if (pumpTo && (!pumpFrom || pumpFrom.State == PartStates.DEAD || pumpTo.vessel != pumpFrom.vessel)) { StopPump(); } } }
void OnVesselWasModified(Vessel vesselModified) { if (vesselModified != this.vessel) { return; } if (linked) { if (linkedStrutModule.vessel != this.vessel) { if (allowDock) { KAS_Shared.DebugWarning("OnVesselWasModified(strut) Source and target vessel are different, docking strut... (allowDock = true)"); KASModuleStrut tmpLinkedStrutMod = linkedStrutModule; Unlink(); LinkTo(tmpLinkedStrutMod, false); } else { KAS_Shared.DebugWarning("OnVesselWasModified(strut) Source and target vessel are different, unlinking strut... (allowDock = false)"); Unlink(); fxSndBroke.audio.Play(); } } } }
protected override void OnJointBreak(float breakForce) { KAS_Shared.DebugWarning("OnJointBreak(Strut) A joint broken on " + part.partInfo.title + " !, force: " + breakForce); Unlink(); fxSndBroke.audio.Play(); base.OnJointBreak(breakForce); }
public override void OnJointBreakFixed() { KAS_Shared.DebugWarning( string.Format("OnJointBreak(Strut) A joint broken on {0}!, force: {1}", part.partInfo.title, breakForce)); Unlink(); fxSndBroke.audio.Play(); }
public void Update() { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.K)) { if (GuiConfigToogle) { Debug.Log("KASAddonDebugMenu - Closing KAS debug tools"); GuiConfigToogle = false; } else { Debug.Log("KASAddonDebugMenu - Opening KAS debug tools"); GuiConfigToogle = true; } } if (GuiConfigToogle) { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Mouse0)) { Debug.Log("KASAddonDebugMenu - On click"); clickedPart = KAS_Shared.GetPartUnderCursor(); if (clickedPart) { moduleWinch = null; moduleGrab = null; moduleMagnet = null; moduleSuctionCup = null; moduleGrapple = null; moduleTimedBomb = null; modulePort = null; moduleAnchor = null; moduleStrut = null; moduleRotor = null; moduleWinch = clickedPart.GetComponent <KASModuleWinch>(); moduleGrab = clickedPart.GetComponent <KASModuleGrab>(); moduleMagnet = clickedPart.GetComponent <KASModuleMagnet>(); moduleSuctionCup = clickedPart.GetComponent <KASModuleSuctionCup>(); moduleGrapple = clickedPart.GetComponent <KASModuleGrapplingHook>(); moduleTimedBomb = clickedPart.GetComponent <KASModuleTimedBomb>(); modulePort = clickedPart.GetComponent <KASModulePort>(); moduleAnchor = clickedPart.GetComponent <KASModuleAnchor>(); moduleStrut = clickedPart.GetComponent <KASModuleStrut>(); moduleRotor = clickedPart.GetComponent <KASModuleRotor>(); } } } if (FlightGlobals.ActiveVessel.heightFromTerrain == -1f) { if (FlightGlobals.ActiveVessel.Landed) { KAS_Shared.DebugWarning("Warning ! ActiveVessel is landed and heightFromTerrain are negative (" + FlightGlobals.ActiveVessel.heightFromTerrain + ")"); } } }
private void OnVesselGoOffRails(Vessel vess) { if (FixedAttach.createJointOnUnpack && (vess == FixedAttach.srcPart.vessel || vess == FixedAttach.tgtPart.vessel)) { KAS_Shared.DebugWarning( "OnUpdate(Core) Fixed attach set and both part unpacked, creating fixed joint..."); AttachFixed(FixedAttach.srcPart, FixedAttach.tgtPart, FixedAttach.savedBreakForce); SetCreateJointOnUnpack(false); } }
private IEnumerator <YieldInstruction> WaitAndRedock() { yield return(null); // If still ok, we can redock now if (part && vessel && linked && linkedStrutModule.vessel != this.vessel && allowDock) { KAS_Shared.DebugWarning("WaitAndRedock(strut) Source and target vessel are different, docking strut... (allowDock = true)"); KASModuleStrut tmpLinkedStrutMod = linkedStrutModule; Unlink(); LinkTo(tmpLinkedStrutMod, false); } }
/// <summary>Stops physics handling on the object.</summary> /// <remarks>Rigidbody on the object gets destroyed.</remarks> public void StopPhysics() { KAS_Shared.DebugLog("StopPhysics(PhysicChild)"); if (physicObj != null) { UnityEngine.Object.Destroy(physicObjRb); physicObjRb = null; physicObj.transform.parent = part.transform; physicObj = null; } else { KAS_Shared.DebugWarning("StopPhysics(PhysicChild) Physic already stopped! Ignore."); } }
private void disableSectionCollision() { KAS_Shared.DisableVesselCollision(this.vessel, this.part.collider); foreach (KeyValuePair <int, SectionInfo> section in sections) { if (section.Value.transform.collider) { KAS_Shared.DisableVesselCollision(this.vessel, section.Value.transform.collider); } else { KAS_Shared.DebugWarning("LoadBoomHead(TelescopicArm) - Section : " + section.Value.transform.name + " do not have any collider !"); } } }
public void Stop() { KAS_Shared.DebugLog("Stop(PhysicChild)"); if (physicActive) { FlightGlobals.removePhysicalObject(physicObj); UnityEngine.Object.Destroy(physicObj.rigidbody); physicObj.transform.parent = this.part.transform; physicActive = false; } else { KAS_Shared.DebugWarning("Stop(PhysicChild) Physic already stopped !"); } }
public void Grab(Vessel kerbalEvaVessel) { //Validation KASModuleGrab grabbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel); if (grabbedPartModule) { if (grabbedPartModule.part.packed) { KAS_Shared.DebugWarning("Grab - cannot drop the current grabbed part ! (packed)"); return; } } //Start grab StartCoroutine(GrabCoroutine(kerbalEvaVessel)); }
private IEnumerator WaitAndAttach(Part partToAttach, Vector3 position, Quaternion rotation, Part toPart = null) { while (!partToAttach.rigidbody) { KAS_Shared.DebugLog("WaitAndAttach(Pointer) - Waiting rigidbody to initialize..."); yield return(new WaitForFixedUpdate()); } KASModuleGrab moduleGrab = partToAttach.GetComponent <KASModuleGrab>(); if (toPart) { KAS_Shared.DebugLog("WaitAndAttach(Pointer) - Rigidbody initialized, setting velocity..."); partToAttach.rigidbody.velocity = toPart.rigidbody.velocity; partToAttach.rigidbody.angularVelocity = toPart.rigidbody.angularVelocity; KAS_Shared.DebugLog("WaitAndAttach(Pointer) - Waiting velocity to apply by waiting 0.1 seconds..."); yield return(new WaitForSeconds(0.1f)); partToAttach.transform.position = position; partToAttach.transform.rotation = rotation; partToAttach.Couple(toPart); if (moduleGrab) { moduleGrab.fxSndAttachPart.audio.Play(); } else { KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, cannot fire sound"); } } else { partToAttach.transform.position = position; partToAttach.transform.rotation = rotation; if (moduleGrab) { moduleGrab.AttachStatic(); moduleGrab.fxSndAttachStatic.audio.Play(); } else { KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, part cannot be attached on static"); } } KAS_Shared.ResetCollisionEnhancer(partToAttach); }
public override void OnUpdate() { base.OnUpdate(); if (!HighLogic.LoadedSceneIsFlight) { return; } if (FixedAttach.createJointOnUnpack) { if (!this.part.packed && !FixedAttach.connectedPart.packed) { KAS_Shared.DebugWarning("OnUpdate(Core) Fixed attach set and both part unpacked, creating fixed joint..."); AttachFixed(FixedAttach.connectedPart, FixedAttach.savedBreakForce); FixedAttach.createJointOnUnpack = false; } } }
// Methods public void Start() { KAS_Shared.DebugLog("Start(PhysicChild)"); if (!physicActive) { physicObj.AddComponent <Rigidbody>(); physicObj.rigidbody.mass = mass; physicObj.transform.parent = null; physicObj.rigidbody.useGravity = true; physicObj.rigidbody.velocity = this.part.rigidbody.velocity; physicObj.rigidbody.angularVelocity = this.part.rigidbody.angularVelocity; FlightGlobals.addPhysicalObject(physicObj); physicActive = true; } else { KAS_Shared.DebugWarning("Start(PhysicChild) Physic already started !"); } }
private IEnumerator WaitAndCheckJoint() { yield return(new WaitForFixedUpdate()); if (attachMode.StaticJoint) { if (StaticAttach.fixedJoint == null) { KAS_Shared.DebugWarning("WaitAndCheckJoint(Core) Static join broken !"); OnJointBreakStatic(); } } if (attachMode.FixedJoint) { if (FixedAttach.fixedJoint == null) { KAS_Shared.DebugWarning("WaitAndCheckJoint(Core) Fixed join broken !"); OnJointBreakFixed(); } } }
public void AttachFixed(Part otherPart, float breakForce) { attachMode.FixedJoint = true; FixedAttach.connectedPart = otherPart; if (!this.part.packed && !otherPart.packed) { KAS_Shared.DebugLog("AttachFixed(Core) Create fixed joint on " + this.part.partInfo.title + " with " + otherPart.partInfo.title); if (FixedAttach.fixedJoint) { Destroy(FixedAttach.fixedJoint); } FixedAttach.fixedJoint = this.part.gameObject.AddComponent <FixedJoint>(); FixedAttach.fixedJoint.connectedBody = otherPart.rigidbody; FixedAttach.fixedJoint.breakForce = breakForce; FixedAttach.fixedJoint.breakTorque = breakForce; } else { FixedAttach.createJointOnUnpack = true; KAS_Shared.DebugWarning("AttachFixed(Core) Cannot create fixed joint as part(s) is packed, delaying to unpack..."); } }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (node.HasNode("FIXEDATTACH")) { ConfigNode FxNode = node.GetNode("FIXEDATTACH"); KAS_Shared.DebugLog("OnLoad(Core) Loading fixed joint info from save..."); if (FxNode.HasValue("srcPartID") && FxNode.HasValue("srcVesselID") && FxNode.HasValue("tgtPartID") && FxNode.HasValue("tgtVesselID") && FxNode.HasValue("breakForce")) { FixedAttach.savedSrcPartID = FxNode.GetValue("srcPartID").ToString(); FixedAttach.savedSrcVesselID = FxNode.GetValue("srcVesselID").ToString(); FixedAttach.savedTgtPartID = FxNode.GetValue("tgtPartID").ToString(); FixedAttach.savedTgtVesselID = FxNode.GetValue("tgtVesselID").ToString(); FixedAttach.savedBreakForce = float.Parse(FxNode.GetValue("breakForce")); attachMode.FixedJoint = true; } else { KAS_Shared.DebugWarning("OnLoad(Core) Missing node value(s)!"); } } if (node.HasNode("DOCKEDVESSEL") && node.HasValue("dockedPartID")) { KAS_Shared.DebugLog("OnLoad(Core) Loading docked info from save..."); vesselInfo = new DockedVesselInfo(); vesselInfo.Load(node.GetNode("DOCKEDVESSEL")); dockedPartID = node.GetValue("dockedPartID").ToString(); attachMode.Docked = true; } if (node.HasValue("StaticJoint")) { attachMode.StaticJoint = true; } }
public void UpdatePointer() { if (!running) { if (pointer) { UnityEngine.Object.Destroy(pointer); } return; } //Cast ray Ray ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (!Physics.Raycast(ray, out hit, 500, 557059)) { if (pointer) { UnityEngine.Object.Destroy(pointer); } return; } //Create pointer if needed if (!pointer) { GameObject modelGo = partToAttach.FindModelTransform("model").gameObject; pointer = Mesh.Instantiate(modelGo) as GameObject; foreach (Collider col in pointer.GetComponentsInChildren <Collider>()) { UnityEngine.Object.Destroy(col); } allModelMr = new List <MeshRenderer>(); // Remove attached tube mesh renderer if any List <MeshRenderer> tmpAllModelMr = new List <MeshRenderer>(pointer.GetComponentsInChildren <MeshRenderer>() as MeshRenderer[]); foreach (MeshRenderer mr in tmpAllModelMr) { if (mr.name == "KAStube" || mr.name == "KASsrcSphere" || mr.name == "KASsrcTube" || mr.name == "KAStgtSphere" || mr.name == "KAStgtTube") { Destroy(mr); continue; } allModelMr.Add(mr); mr.material = new Material(Shader.Find("Transparent/Diffuse")); } pointerNodeTransform = new GameObject("KASPointerPartNode").transform; pointerNodeTransform.parent = pointer.transform; pointerNodeTransform.localPosition = partToAttach.srfAttachNode.position; pointerNodeTransform.localRotation = Quaternion.Inverse(Quaternion.LookRotation(partToAttach.srfAttachNode.orientation, Vector3.up)); } //Set default color Color color = Color.green; // Check if object is valid bool isValidObj = false; Part hitPart = null; KerbalEVA hitEva = null; if (hit.rigidbody) { hitPart = hit.rigidbody.GetComponent <Part>(); hitEva = hit.rigidbody.GetComponent <KerbalEVA>(); if (hitPart && allowPart && !hitEva & hitPart != partToAttach) { isValidObj = true; } if (hitEva && allowEva) { isValidObj = true; } } if (!hitPart && !hitEva && allowStatic) { isValidObj = true; } //Check distance bool isValidSourceDist = true; if (sourceTransform) { isValidSourceDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, sourceTransform.position) <= maxDist; } bool isValidTargetDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, hit.point) <= maxDist; //Set color if (!isValidObj) { color = Color.red; } else if (!isValidSourceDist || !isValidTargetDist) { color = Color.yellow; } color.a = 0.5f; foreach (MeshRenderer mr in allModelMr) { mr.material.color = color; } //Rotation keys Vector3 delta = new Vector3(0, 0, 1); if (Input.GetKey(KeyCode.LeftAlt)) { delta = new Vector3(1, 0, 0); } else if (Input.GetKey(KeyCode.RightAlt)) { delta = new Vector3(0, -1, 0); } if (Input.GetKeyDown(KASAddonControlKey.rotateLeftKey.ToLower())) { customRot -= delta * 15; } if (Input.GetKeyDown(KASAddonControlKey.rotateRightKey.ToLower())) { customRot += delta * 15; } Quaternion rotAdjust = Quaternion.Euler(0, 0, customRot.z) * Quaternion.Euler(customRot.x, customRot.y, 0); KAS_Shared.MoveAlign(pointer.transform, pointerNodeTransform, hit, rotAdjust); //Attach on click if (Input.GetKeyDown(KeyCode.Mouse0)) { KAS_Shared.DebugLog("Attachment started..."); if (!isValidObj) { ScreenMessages.PostScreenMessage("Can't attach, target is not allowed !"); audioBipWrong.Play(); return; } if (!isValidSourceDist) { ScreenMessages.PostScreenMessage("Can't attach, too far from source !"); audioBipWrong.Play(); return; } if (!isValidTargetDist) { ScreenMessages.PostScreenMessage("Can't attach, too far from target !"); audioBipWrong.Play(); return; } KASModuleGrab modulegrab = partToAttach.GetComponent <KASModuleGrab>(); //Move and attach mode if (pointerMode == PointerMode.MoveAndAttach) { // Drop and detach part if needed if (modulegrab) { if (modulegrab.grabbed) { modulegrab.Drop(); } modulegrab.Detach(); } KASModuleWinch connectedWinch = KAS_Shared.GetConnectedWinch(partToAttach); if (!connectedWinch) { KAS_Shared.DecoupleFromAll(partToAttach); } //Move part partToAttach.transform.position = pointer.transform.position; partToAttach.transform.rotation = pointer.transform.rotation; if (connectedWinch) { //Set cable lenght to real lenght connectedWinch.cableJointLength = connectedWinch.cableRealLenght; } KAS_Shared.ResetCollisionEnhancer(partToAttach); if (msgOnly) { KAS_Shared.DebugLog("UpdatePointer(Pointer) Attach using send message"); if (hitPart) { partToAttach.SendMessage("OnAttachPart", hitPart, SendMessageOptions.DontRequireReceiver); } else { partToAttach.SendMessage("OnAttachStatic", SendMessageOptions.DontRequireReceiver); } } else { KAS_Shared.DebugLog("UpdatePointer(Pointer) Attach with couple or static method"); if (!hitPart && !hitEva) { if (modulegrab) { modulegrab.AttachStatic(); modulegrab.fxSndAttachStatic.audio.Play(); } else { KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, part cannot be attached on static"); } } else { partToAttach.Couple(hitPart); if (modulegrab) { modulegrab.fxSndAttachPart.audio.Play(); } else { KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, cannot fire sound"); } } partToAttach.SendMessage("OnAttach", SendMessageOptions.DontRequireReceiver); } } if (pointerMode == PointerMode.CopyAndAttach) { // Not tested ! Part newPart = KAS_Shared.CreatePart(partToAttach.partInfo, pointer.transform.position, pointer.transform.rotation, partToAttach); if (msgOnly) { if (hitPart) { StartCoroutine(WaitAndSendMsg(newPart, pointer.transform.position, pointer.transform.rotation, hitPart)); } else { StartCoroutine(WaitAndSendMsg(newPart, pointer.transform.position, pointer.transform.rotation)); } } else { if (!hitPart && !hitEva) { StartCoroutine(WaitAndAttach(newPart, pointer.transform.position, pointer.transform.rotation, hitPart)); } else { StartCoroutine(WaitAndAttach(newPart, pointer.transform.position, pointer.transform.rotation)); } } } running = false; } }
public void LoadBoomHead() { if (savedSectionsLocalPos.Count > 0) { //Reset section(s) to org pos foreach (KeyValuePair <int, SectionInfo> section in sections) { section.Value.transform.position = this.part.transform.TransformPoint(section.Value.orgLocalPos); } } KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) Create physical object..."); boomHeadPhysicModule = this.part.gameObject.GetComponent <KASModulePhysicChild>(); if (!boomHeadPhysicModule) { KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - KASModulePhysicChild do not exist, adding it..."); boomHeadPhysicModule = this.part.gameObject.AddComponent <KASModulePhysicChild>(); } boomHeadPhysicModule.mass = boomHeadMass; boomHeadPhysicModule.physicObj = sections[0].transform.gameObject; boomHeadPhysicModule.Start(); orgBoomHeadMass = this.part.mass; float newMass = this.part.mass - boomHeadMass; if (newMass > 0) { this.part.mass = newMass; } else { KAS_Shared.DebugWarning("LoadBoomHead(TelescopicArm) - Mass of the boom head is greater than the part !"); } KAS_Shared.DebugLog("LoadRotor - Disable collision..."); disableSectionCollision(); KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Create configurable joint..."); slideJoint = this.part.gameObject.AddComponent <ConfigurableJoint>(); slideJoint.connectedBody = sections[0].transform.rigidbody; slideJoint.axis = Vector3.zero; slideJoint.secondaryAxis = Vector3.zero; slideJoint.breakForce = breakForce; slideJoint.breakTorque = breakForce; slideJoint.angularXMotion = ConfigurableJointMotion.Locked; slideJoint.angularYMotion = ConfigurableJointMotion.Locked; slideJoint.angularZMotion = ConfigurableJointMotion.Locked; slideJoint.xMotion = ConfigurableJointMotion.Locked; slideJoint.yMotion = ConfigurableJointMotion.Locked; slideJoint.zMotion = ConfigurableJointMotion.Locked; if (direction.x != 0) { slideJoint.xMotion = ConfigurableJointMotion.Limited; driveWay = direction.x; KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to x axis with driveWay set to : " + driveWay); } else if (direction.y != 0) { slideJoint.yMotion = ConfigurableJointMotion.Limited; driveWay = direction.y; KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to y axis with driveWay set to : " + driveWay); } else if (direction.z != 0) { slideJoint.zMotion = ConfigurableJointMotion.Limited; driveWay = direction.z; KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Direction set to z axis with driveWay set to : " + driveWay); } JointDrive drv = new JointDrive(); drv.mode = JointDriveMode.PositionAndVelocity; drv.positionSpring = driveSpring; drv.positionDamper = driveDamper; drv.maximumForce = driveForce; slideJoint.xDrive = slideJoint.yDrive = slideJoint.zDrive = drv; SoftJointLimit jointLimit = new SoftJointLimit(); jointLimit.limit = sectionTotalLenght; jointLimit.damper = 200; jointLimit.spring = 1000; jointLimit.bounciness = 1; slideJoint.linearLimit = jointLimit; if (savedSectionsLocalPos.Count > 0) { KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Re-set section position from save"); float sumLenght = 0; foreach (KeyValuePair <int, SectionInfo> section in sections) { KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Move section " + section.Key + " to local position : " + section.Value.savedLocalPos); section.Value.transform.position = this.part.transform.TransformPoint(section.Value.savedLocalPos); sumLenght += section.Value.lenght; if (headPos > sumLenght) { KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Parent section " + sections[section.Key + 1].transform.name + " to : " + section.Value.transform.name); sections[section.Key + 1].transform.parent = section.Value.transform; } } } // Get boom head 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("LoadBoomHead(TelescopicArm) - Boom head attach node added : " + an.id); attachNodes.Add(an); if (an.attachedPart) { KAS_Shared.DebugLog("LoadBoomHead(TelescopicArm) - Setting boom head 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 = sections[0].transform.rigidbody; fixedJnts.Add(fjnt); } } } SetTargetPos(targetPos); boomHeadLoaded = true; }
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; }
public void ContextMenuStore() { KASModuleGrab moduleEvaGrab = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel); if (!moduleEvaGrab || moduleEvaGrab.part.packed) { ScreenMessages.PostScreenMessage("You need to grab a part before", 2, ScreenMessageStyle.UPPER_CENTER); KAS_Shared.DebugWarning("ContextMenuStore - GetGrabbedPartModule return null !"); return; } // Select the nearest compatible bay float shorterDist = Mathf.Infinity; AttachNode nearestBayNode = null; foreach (KeyValuePair <AttachNode, List <string> > bay in bays) { if (bay.Value != null) { if (!bay.Value.Contains(moduleEvaGrab.bayType)) { KAS_Shared.DebugWarning("ContextMenuStore - Part type : " + moduleEvaGrab.bayType + " is not allowed | Attach node : " + bay.Key.id); foreach (string type in bay.Value) { KAS_Shared.DebugWarning("ContextMenuStore - Allowed type : " + type); } continue; } } if (bay.Key.attachedPart) { KAS_Shared.DebugWarning("ContextMenuStore - This node are used"); continue; } float distToBay = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, bay.Key.nodeTransform.position); if (distToBay <= shorterDist) { shorterDist = distToBay; nearestBayNode = bay.Key; } } if (nearestBayNode == null) { ScreenMessages.PostScreenMessage("Part is not compatible or there is no free space", 2, ScreenMessageStyle.UPPER_CENTER); KAS_Shared.DebugWarning("ContextMenuStore - Part is not compatible or there is no free space"); return; } AttachNode grabbedPartAn = moduleEvaGrab.part.findAttachNode(moduleEvaGrab.bayNode); if (grabbedPartAn == null) { KAS_Shared.DebugError("ContextMenuStore - Grabbed part bay node not found !"); return; } KAS_Shared.DebugLog("ContextMenuStore - Drop part..."); moduleEvaGrab.Drop(); KAS_Shared.DebugLog("ContextMenuStore - Add node transform if not exist..."); KAS_Shared.AddNodeTransform(moduleEvaGrab.part, grabbedPartAn); KAS_Shared.DebugLog("ContextMenuStore - Move part..."); KAS_Shared.MoveAlign(moduleEvaGrab.part.transform, grabbedPartAn.nodeTransform, nearestBayNode.nodeTransform); moduleEvaGrab.part.transform.rotation *= Quaternion.Euler(moduleEvaGrab.bayRot); //Couple part with bay KAS_Shared.DebugLog("ContextMenuStore - Couple part with bay..."); moduleEvaGrab.part.Couple(this.part); nearestBayNode.attachedPart = moduleEvaGrab.part; fxSndStore.audio.Play(); moduleEvaGrab.part.SendMessage("OnBayStore", SendMessageOptions.DontRequireReceiver); }
public override void OnJointBreakFixed() { KAS_Shared.DebugWarning("Disable magnet..."); MagnetActive = false; base.OnJointBreakFixed(); }
private bool AlignEvaPosition(Vessel kerbalEvaVessel) { //Get eva transform evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, evaTransformName); if (!evaCollider) { KAS_Shared.DebugLog("Grab - " + evaTransformName + "transform not found on eva !"); return(false); } //Get attach node if (attachNodeName == null || attachNodeName == "") { if (this.part.srfAttachNode == null) { KAS_Shared.DebugLog("Grab - surface attach node cannot be found on the part !"); return(false); } KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode); partNode = this.part.srfAttachNode; } else { AttachNode an = this.part.findAttachNode(attachNodeName); if (an == null) { KAS_Shared.DebugLog("Grab - " + attachNodeName + " node cannot be found on the part !"); return(false); } KAS_Shared.AddNodeTransform(this.part, an); partNode = an; } //Send message to other modules base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); //Drop grabbed part on eva if needed KASModuleGrab tmpGrabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel); if (tmpGrabbbedPartModule) { if (tmpGrabbbedPartModule.part.packed) { KAS_Shared.DebugWarning("Grab - cannot drop an incompletely grabbed part!"); return(false); } KAS_Shared.DebugWarning("Grab - Drop current grabbed part"); tmpGrabbbedPartModule.Drop(); } if (evaNodeTransform) { Destroy(evaNodeTransform.gameObject); } evaNodeTransform = new GameObject("KASEvaNode").transform; evaNodeTransform.parent = evaCollider.transform; evaNodeTransform.localPosition = evaPartPos; evaNodeTransform.rotation = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaPartDir); KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform); if (this.part.vessel == kerbalEvaVessel) { this.part.UpdateOrgPosAndRot(kerbalEvaVessel.rootPart); } return(true); }
public void Grab(Vessel kerbalEvaVessel) { KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name); //Get eva transform evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, evaTransformName); if (!evaCollider) { KAS_Shared.DebugLog("Grab - " + evaTransformName + "transform not found on eva !"); return; } //Get attach node if (attachNodeName == null || attachNodeName == "") { if (this.part.srfAttachNode == null) { KAS_Shared.DebugLog("Grab - surface attach node cannot be found on the part !"); return; } KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode); partNode = this.part.srfAttachNode; } else { AttachNode an = this.part.findAttachNode(attachNodeName); if (an == null) { KAS_Shared.DebugLog("Grab - " + attachNodeName + " node cannot be found on the part !"); return; } KAS_Shared.AddNodeTransform(this.part, an); partNode = an; } //Send message to other modules base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); //Drop grabbed part on eva if needed KASModuleGrab tmpGrabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel); if (tmpGrabbbedPartModule) { KAS_Shared.DebugWarning("Grab - Drop current grabbed part"); tmpGrabbbedPartModule.Drop(); } evaNodeTransform = new GameObject("KASEvaNode").transform; evaNodeTransform.parent = evaCollider.transform; evaNodeTransform.localPosition = evaPartPos; evaNodeTransform.rotation = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaPartDir); KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform); //Grab winch connected head if any KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part); if (moduleWinch) { KASModulePort modulePort = this.part.GetComponent <KASModulePort>(); moduleWinch.UnplugHead(false); moduleWinch.GrabHead(kerbalEvaVessel, modulePort); } List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]); foreach (Collider col in allColliders) { col.isTrigger = true; } Detach(); KAS_Shared.DecoupleFromAll(this.part); this.part.Couple(kerbalEvaVessel.rootPart); //Destroy joint to avoid buggy eva move Destroy(this.part.attachJoint); this.part.rigidbody.velocity = kerbalEvaVessel.rootPart.rigidbody.velocity; if (physicJoint) { if (evaJoint) { Destroy(evaJoint); } evaJoint = this.part.gameObject.AddComponent <FixedJoint>(); evaJoint.connectedBody = evaCollider.attachedRigidbody; evaJoint.breakForce = 5; evaJoint.breakTorque = 5; } else { this.part.physicalSignificance = Part.PhysicalSignificance.NONE; this.part.transform.parent = evaNodeTransform; this.part.rigidbody.isKinematic = true; } //Add grabbed part mass to eva if (addPartMass && !physicJoint) { orgKerbalMass = kerbalEvaVessel.rootPart.mass; kerbalEvaVessel.rootPart.mass += this.part.mass; } evaHolderVesselName = kerbalEvaVessel.vesselName; evaHolderPart = kerbalEvaVessel.rootPart; grabbed = true; RefreshContextMenu(); //Play grab sound fxSndGrab.audio.Play(); base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); }
public void Drop() { if (grabbed) { KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name); base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver); if (this.part.vessel.isEVA) { this.part.decouple(); } //Remove created joints between eva and part if exist KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart); KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart); List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]); foreach (Collider col in allColliders) { col.isTrigger = false; } if (customGroundPos && evaHolderPart.checkLanded()) { KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot); } else { KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform); } if (evaNodeTransform) { Destroy(evaNodeTransform.gameObject); } if (evaJoint) { Destroy(evaJoint); } this.part.transform.parent = null; this.part.rigidbody.isKinematic = false; this.part.physicalSignificance = Part.PhysicalSignificance.FULL; this.part.rigidbody.velocity = evaHolderPart.rigidbody.velocity; this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity; if (addPartMass & !physicJoint) { evaHolderPart.mass = orgKerbalMass; } KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel); if (grabbedWinchHead) { if (grabbedWinchHead.grabbedPortModule) { KAS_Shared.DebugLog("Drop - Grabbed part have a port connected"); grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false); } } evaJoint = null; evaNodeTransform = null; evaHolderVesselName = null; evaHolderPart = null; grabbed = false; RefreshContextMenu(); //Send drop message to all child objects base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver); } else { KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop..."); } }