A module for a disconnected object that should be affected by the normal physics.
It's expected the object is somehow related to the part. If part gets destroyed then the physical child get destroyed as well.
Inheritance: PartModule
コード例 #1
0
        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;
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: KASModuleRotor.cs プロジェクト: ErzengelLichtes/KAS
        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;
        }
コード例 #4
0
ファイル: KASModuleWinch.cs プロジェクト: ACCBizon/KAS
 public void SetHeadToPhysic(bool active)
 {
     if (active)
     {
         KAS_Shared.DebugLog("SetHeadToPhysic(Winch) - Create physical object");
         headPhysicModule = this.part.gameObject.GetComponent<KASModulePhysicChild>();
         if (!headPhysicModule)
         {
             KAS_Shared.DebugLog("SetHeadToPhysic(Winch) - KASModulePhysicChild do not exist, adding it...");
             headPhysicModule = this.part.gameObject.AddComponent<KASModulePhysicChild>();
         }
         headPhysicModule.mass = headMass;
         headPhysicModule.physicObj = headTransform.gameObject;
         headPhysicModule.Start();
     }
     else
     {
         headPhysicModule.Stop();
         Destroy(headPhysicModule);
     }
 }
コード例 #5
0
ファイル: KASModuleWinch.cs プロジェクト: KospY/KAS
 public void SetHeadToPhysic(bool active, bool delayPhysics = false)
 {
     if (active) {
       KAS_Shared.DebugLog("SetHeadToPhysic(Winch) - Create physical object");
       headPhysicModule = part.gameObject.GetComponent<KASModulePhysicChild>();
       if (!headPhysicModule) {
     KAS_Shared.DebugLog(
     "SetHeadToPhysic(Winch) - KASModulePhysicChild do not exist, adding it...");
     headPhysicModule = part.gameObject.AddComponent<KASModulePhysicChild>();
       }
       headPhysicModule.StartPhysics(headTransform.gameObject, headMass, delayPhysics: delayPhysics);
     } else {
       // Yes, it must be immediate. Otherwise, the further code will try to behave on the module.
       DestroyImmediate(headPhysicModule);
     }
 }
コード例 #6
0
        public void LoadBoomHead()
        {
            if (savedSectionsLocalPos.Count > 0) {
              //Reset section(s) to org pos
              foreach (KeyValuePair<int, SectionInfo> section in sections) {
            section.Value.transform.position = 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.StartPhysics(sections[0].transform.gameObject, boomHeadMass);

            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.GetComponent<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;

            var jointLimit = new SoftJointLimit();
            jointLimit.limit = sectionTotalLenght;
            jointLimit.bounciness = 1;
            slideJoint.linearLimit = jointLimit;
            slideJoint.linearLimitSpring = new SoftJointLimitSpring() {
              damper = 200,
              spring = 1000
            };

            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 =
            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.GetComponent<Rigidbody>();
              fixedJnts.Add(fjnt);
            }
              }
            }
            SetTargetPos(targetPos);
            boomHeadLoaded = true;
        }