RemoveFixedJointBetween() public static method

public static RemoveFixedJointBetween ( Part part1, Part part2 ) : void
part1 Part
part2 Part
return void
        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;
        }
Example #2
0
        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...");
            }
        }
Example #3
0
        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;
        }
Example #4
0
        public void Drop(bool forAttach = false)
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);

                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA || grab_pending)
                {
                    this.part.decouple();
                }

                if (grab_pending)
                {
                    Destroy(evaNodeTransform.gameObject);
                    evaNodeTransform    = null;
                    evaHolderVesselName = null;
                    evaHolderPart       = null;
                    grabbed             = grab_pending = false;
                    RefreshContextMenu();
                    return;
                }

                //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 = (keepTriggers != null && keepTriggers.Contains(col));
                }

                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.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                KAS_Shared.ResetCollisionEnhancer(this.part);

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule && grabbedWinchHead.grabbedPortModule.part == part)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");

                        if (forAttach)
                        {
                            // Docked causes big problems when the part is later coupled
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugUndocked, fireSound: false);
                        }
                        else
                        {
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                        }
                    }
                }

                GameEvents.onCrewBoardVessel.Remove(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel));

                syncGrab            = false;
                keepTriggers        = null;
                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = grab_pending = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }