Example #1
0
 public override void Destroy()
 {
     //UnsetModuleStructuralNode(nodes[0], structNodeMan[0]);
     //UnsetModuleStructuralNode(nodes[1], structNodeMan[1]);
     base.Destroy();
     ConnectedLivingSpacesCompatibility.RequestRemoveConnection(parts[0], parts[1]);
     ReCouplerUtils.onReCouplerEditorJointBroken.Fire(new GameEvents.FromToAction <Part, Part>(this.parts[0], this.parts[1]));
     GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
 }
Example #2
0
            public override void Destroy()
            {
                if (_isTrackingDockingPorts)
                {
                    return;
                }

                log.debug("Destroying a link.");
                if (joint != null)
                {
                    GameObject.Destroy(joint);
                }

                base.Destroy();

                if (oldCrossfeedSets.Count > 0)
                {
                    parts[0].crossfeedPartSet = oldCrossfeedSets[0];
                    parts[1].crossfeedPartSet = oldCrossfeedSets[1];
                }

                UnsetModuleStructuralNode(nodes[0], structNodeMan[0]);
                UnsetModuleStructuralNode(nodes[1], structNodeMan[1]);

                if (this.parts[0] != null && this.parts[1] != null)
                {
                    ConnectedLivingSpacesCompatibility.RequestRemoveConnection(this.parts[0], this.parts[1]);
                }

                if (this.parts[0] != null)
                {
                    ReCouplerUtils.onReCouplerJointBroken.Fire(new GameEvents.HostedFromToAction <Vessel, Part>(this.parts[0].vessel, this.parts[0], this.parts[1]));
                }
                else if (this.parts[1] != null)
                {
                    ReCouplerUtils.onReCouplerJointBroken.Fire(new GameEvents.HostedFromToAction <Vessel, Part>(this.parts[1].vessel, this.parts[0], this.parts[1]));
                }
                else
                {
                    ReCouplerUtils.onReCouplerJointBroken.Fire(new GameEvents.HostedFromToAction <Vessel, Part>(null, this.parts[0], this.parts[1]));
                }

                if (parts[0] != null && parts[0].vessel != null)
                {
                    GameEvents.onVesselWasModified.Fire(parts[0].vessel);
                }
                else if (parts[1] != null && parts[1].vessel != null)
                {
                    GameEvents.onVesselWasModified.Fire(parts[1].vessel);
                }
            }
Example #3
0
            public ConfigurableJoint CreateLink()
            {
                if (this.joint != null)
                {
                    log.warning("This link already has a joint object.");
                    return(this.joint);
                }
                if (_isTrackingDockingPorts)
                {
                    this.joint = new ConfigurableJoint();
                    return(this.joint);
                }

                try
                {
                    AttachNode parent     = this.nodes[0];
                    AttachNode child      = this.nodes[1];
                    Part       parentPart = this.parts[0];
                    Part       childPart  = this.parts[1];

                    log.debug("Creating joint between " + parentPart.name + " and " + childPart.name + ".");

                    if (parentPart.Rigidbody == null)
                    {
                        log.error("parentPart body is null :o");
                    }
                    if (childPart.Rigidbody == null)
                    {
                        log.error("childPart body is null :o");
                    }

                    ConfigurableJoint newJoint;

                    newJoint = childPart.gameObject.AddComponent <ConfigurableJoint>();
                    newJoint.connectedBody   = parentPart.Rigidbody;
                    newJoint.anchor          = Vector3.zero;        // There's probably a better anchor point, like the attachNode...
                    newJoint.connectedAnchor = Vector3.zero;

                    newJoint.autoConfigureConnectedAnchor = false;  // Probably don't need.
                    newJoint.axis            = Vector3.up;
                    newJoint.secondaryAxis   = Vector3.left;
                    newJoint.enableCollision = false;               // Probably don't need.

                    newJoint.breakForce  = float.PositiveInfinity;  //Math.Min(parentPart.breakingForce, childPart.breakingForce);
                    newJoint.breakTorque = float.PositiveInfinity;  //Math.Min(parentPart.breakingTorque, childPart.breakingTorque);

                    newJoint.angularXMotion = ConfigurableJointMotion.Limited;
                    newJoint.angularYMotion = ConfigurableJointMotion.Limited;
                    newJoint.angularZMotion = ConfigurableJointMotion.Limited;

                    JointDrive linearDrive = new JointDrive();
                    linearDrive.maximumForce   = 1E20f;
                    linearDrive.positionDamper = 0;
                    linearDrive.positionSpring = 1E20f;
                    newJoint.xDrive            = linearDrive;
                    newJoint.yDrive            = linearDrive;
                    newJoint.zDrive            = linearDrive;

                    newJoint.projectionDistance = 0.1f;
                    newJoint.projectionAngle    = 180;
                    newJoint.projectionMode     = JointProjectionMode.None;

                    newJoint.rotationDriveMode     = RotationDriveMode.XYAndZ;
                    newJoint.swapBodies            = false;
                    newJoint.targetAngularVelocity = Vector3.zero;
                    newJoint.targetPosition        = Vector3.zero;
                    newJoint.targetVelocity        = Vector3.zero;
                    newJoint.targetRotation        = new Quaternion(0, 0, 0, 1);

                    JointDrive angularDrive = new JointDrive();
                    angularDrive.maximumForce   = 1E20f;
                    angularDrive.positionSpring = 60000;
                    angularDrive.positionDamper = 0;
                    newJoint.angularXDrive      = angularDrive;
                    newJoint.angularYZDrive     = angularDrive;

                    SoftJointLimitSpring zeroSpring = new SoftJointLimitSpring();
                    zeroSpring.spring             = 0;
                    zeroSpring.damper             = 0;
                    newJoint.angularXLimitSpring  = zeroSpring;
                    newJoint.angularYZLimitSpring = zeroSpring;

                    SoftJointLimit angleSoftLimit = new SoftJointLimit();
                    angleSoftLimit.bounciness      = 0;
                    angleSoftLimit.contactDistance = 0;
                    angleSoftLimit.limit           = 177;
                    newJoint.angularYLimit         = angleSoftLimit;
                    newJoint.angularZLimit         = angleSoftLimit;
                    newJoint.highAngularXLimit     = angleSoftLimit;
                    newJoint.lowAngularXLimit      = angleSoftLimit;

                    this.joint = newJoint;
                }
                catch (Exception ex)
                {
                    log.error("Could not create physical joint: " + ex);
                }
                this.SetNodes();

                ConnectedLivingSpacesCompatibility.RequestAddConnection(this.parts[0], this.parts[1]);
                ReCouplerUtils.onReCouplerJointFormed.Fire(new GameEvents.HostedFromToAction <Vessel, Part>(parts[0].vessel, parts[0], parts[1]));
                return(this.joint);
            }
Example #4
0
 public EditorJointTracker(AbstractJointTracker parent) : base(parent.nodes[0], parent.nodes[1])
 {
     this.SetNodes();
     ConnectedLivingSpacesCompatibility.RequestAddConnection(parts[0], parts[1]);
     ReCouplerUtils.onReCouplerEditorJointFormed.Fire(new GameEvents.FromToAction <Part, Part>(this.parts[0], this.parts[1]));
 }