Exemplo n.º 1
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);
            }
Exemplo n.º 2
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]));
 }