Пример #1
0
        public void createAttachNode(Part latch)
        {
            printDebug($"creating attachNode from part {part.flightID} to part {latch.flightID}");

            part.attachJoint.Joint.breakForce  = Mathf.Infinity;
            part.attachJoint.Joint.breakTorque = Mathf.Infinity;

            latch.attachJoint.Joint.breakForce  = Mathf.Infinity;
            latch.attachJoint.Joint.breakTorque = Mathf.Infinity;

            cJoint = part.gameObject.AddComponent <ConfigurableJoint>();
            cJoint.connectedBody      = latch.GetComponent <Rigidbody>();
            cJoint.breakForce         = cJoint.breakTorque = Mathf.Infinity;
            cJoint.xMotion            = ConfigurableJointMotion.Locked;
            cJoint.yMotion            = ConfigurableJointMotion.Locked;
            cJoint.zMotion            = ConfigurableJointMotion.Locked;
            cJoint.angularXMotion     = ConfigurableJointMotion.Locked;
            cJoint.angularYMotion     = ConfigurableJointMotion.Locked;
            cJoint.angularZMotion     = ConfigurableJointMotion.Locked;
            cJoint.projectionAngle    = 0f;
            cJoint.projectionDistance = 0f;
            cJoint.targetPosition     = latch.transform.position;
            cJoint.anchor             = part.transform.position;

            // FIXME: Spring or Fixed?
            printDebug($"sJoint: {sJoint}");
            if (sJoint == null)
            {
                try
                {
                    sJoint               = part.parent.gameObject.AddComponent <SpringJoint>();
                    sJoint.damper        = lockStrength / 2f;
                    sJoint.maxDistance   = 0;
                    sJoint.minDistance   = 0;
                    sJoint.spring        = lockStrength * 10f;
                    sJoint.tolerance     = 0.005f;
                    sJoint.connectedBody = latch.parent.GetComponent <Rigidbody>();
                }
                catch (NullReferenceException)
                {
                    // in case one of the parents doesn't exist
                    printDebug("Failed to create spring joint");
                    sJoint = null;
                }
                printDebug($"Created spring joint {sJoint}");
            }

            printDebug($"Created configurable joint with id={cJoint.GetInstanceID()}; joint={cJoint}");

            Vector3 normDir = (part.transform.position - latch.transform.position).normalized;

            attachNode                = new AttachNode();
            attachNode.id             = Guid.NewGuid().ToString();
            attachNode.attachedPart   = latch;
            attachNode.owner          = part;
            attachNode.breakingForce  = lockStrength;
            attachNode.breakingTorque = lockStrength;
            attachNode.position       = latch.partTransform.InverseTransformPoint(latch.partTransform.position);
            attachNode.orientation    = latch.partTransform.InverseTransformDirection(normDir);
            attachNode.size           = 1;
            attachNode.ResourceXFeed  = false;
            attachNode.attachMethod   = AttachNodeMethod.FIXED_JOINT;
            part.attachNodes.Add(attachNode);
            attachNode.owner = part;
            lockJoint        = PartJoint.Create(part, latch, attachNode, null, AttachModes.SRF_ATTACH);
            printDebug($"Created lockJoint with id={lockJoint.GetInstanceID()}; joint={lockJoint}");
        }
Пример #2
0
        private void AddConfigurableJoint(ConfigurableJoint cj)
        {
            if (!dumped.Add(cj))
            {
                return;
            }

            sb.AppendLine($@"--- !u!153 &{cj.GetInstanceID()}
ConfigurableJoint:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {{fileID: 0}}
  m_PrefabInternal: {{fileID: 0}}
  m_GameObject: {{fileID: {cj.gameObject.GetInstanceID()}}}
  m_ConnectedBody: {{fileID: {cj.connectedBody?.GetInstanceID() ?? 0}}}
  m_Anchor: {Stringify(cj.anchor)}
  m_Axis: {Stringify(cj.axis)}
  m_AutoConfigureConnectedAnchor: {(cj.autoConfigureConnectedAnchor ? 1 : 0)}
  m_ConnectedAnchor: {Stringify(cj.connectedAnchor)}
  serializedVersion: 2
  m_SecondaryAxis: {Stringify(cj.secondaryAxis)}
  m_XMotion: {(int)cj.xMotion}
  m_YMotion: {(int)cj.yMotion}
  m_ZMotion: {(int)cj.zMotion}
  m_AngularXMotion: {(int)cj.angularXMotion}
  m_AngularYMotion: {(int)cj.angularYMotion}
  m_AngularZMotion: {(int)cj.angularZMotion}
  m_LinearLimitSpring:
    spring: {cj.linearLimitSpring.spring}
    damper: {cj.linearLimitSpring.damper}
  m_LinearLimit:
    limit: {cj.linearLimit.limit}
    bounciness: {cj.linearLimit.bounciness}
    contactDistance: {cj.linearLimit.contactDistance}
  m_AngularXLimitSpring:
    spring: {cj.angularXLimitSpring.spring}
    damper: {cj.angularXLimitSpring.damper}
  m_LowAngularXLimit:
    limit: {cj.lowAngularXLimit.limit}
    bounciness: {cj.lowAngularXLimit.bounciness}
    contactDistance: {cj.lowAngularXLimit.contactDistance}
  m_HighAngularXLimit:
    limit: {cj.highAngularXLimit.limit}
    bounciness: {cj.highAngularXLimit.bounciness}
    contactDistance: {cj.highAngularXLimit.contactDistance}
  m_AngularYZLimitSpring:
    spring: {cj.angularYZLimitSpring.spring}
    damper: {cj.angularYZLimitSpring.damper}
  m_AngularYLimit:
    limit: {cj.angularYLimit.limit}
    bounciness: {cj.angularYLimit.bounciness}
    contactDistance: {cj.angularYLimit.contactDistance}
  m_AngularZLimit:
    limit: {cj.angularZLimit.limit}
    bounciness: {cj.angularZLimit.bounciness}
    contactDistance: {cj.angularZLimit.contactDistance}
  m_TargetPosition: {Stringify(cj.targetPosition)}
  m_TargetVelocity: {Stringify(cj.targetVelocity)}
  m_XDrive:
    serializedVersion: 3
    positionSpring: {cj.xDrive.positionSpring}
    positionDamper: {cj.xDrive.positionDamper}
    maximumForce: {cj.xDrive.maximumForce}
  m_YDrive:
    serializedVersion: 3
    positionSpring: {cj.yDrive.positionSpring}
    positionDamper: {cj.yDrive.positionDamper}
    maximumForce: {cj.yDrive.maximumForce}
  m_ZDrive:
    serializedVersion: 3
    positionSpring: {cj.zDrive.positionSpring}
    positionDamper: {cj.zDrive.positionDamper}
    maximumForce: {cj.zDrive.maximumForce}
  m_TargetRotation: {Stringify(cj.targetRotation)}
  m_TargetAngularVelocity: {Stringify(cj.targetAngularVelocity)}
  m_RotationDriveMode: {(int)cj.rotationDriveMode}
  m_AngularXDrive:
    serializedVersion: 3
    positionSpring: {cj.angularXDrive.positionSpring}
    positionDamper: {cj.angularXDrive.positionDamper}
    maximumForce: {cj.angularXDrive.maximumForce}
  m_AngularYZDrive:
    serializedVersion: 3
    positionSpring: {cj.angularYZDrive.positionSpring}
    positionDamper: {cj.angularYZDrive.positionDamper}
    maximumForce: {cj.angularYZDrive.maximumForce}
  m_SlerpDrive:
    serializedVersion: 3
    positionSpring: {cj.slerpDrive.positionSpring}
    positionDamper: {cj.slerpDrive.positionDamper}
    maximumForce: {cj.slerpDrive.maximumForce}
  m_ProjectionMode: {(int)cj.projectionMode}
  m_ProjectionDistance: {cj.projectionDistance}
  m_ProjectionAngle: {cj.projectionAngle}
  m_ConfiguredInWorldSpace: {(cj.configuredInWorldSpace ? 1 : 0)}
  m_SwapBodies: {(cj.swapBodies ? 1 : 0)}
  m_BreakForce: {cj.breakForce}
  m_BreakTorque: {cj.breakTorque}
  m_EnableCollision: {(cj.enableCollision ? 1 : 0)}
  m_EnablePreprocessing: {(cj.enablePreprocessing ? 1 : 0)}
  m_MassScale: {cj.massScale}
  m_ConnectedMassScale: {cj.connectedMassScale}");
        }