Exemple #1
0
        private void PerformWeld(WeldingData wData, bool compress, bool fixRotation)
        {
            var nodeA = NodeUtilities.GetLinkingNode(wData.LinkedPartA, wData.DockingPortA);
            var nodeB = NodeUtilities.GetLinkingNode(wData.LinkedPartB, wData.DockingPortB);

            var offset   = GetOffset(wData);
            var rotation = GetRotation(wData);

            if (fixRotation)
            {
                wData.LinkedPartB.transform.Rotate(rotation, Space.Self);
            }

            NodeUtilities.DetachPart(wData.DockingPortA);
            NodeUtilities.DetachPart(wData.DockingPortB);

            NodeUtilities.SwapLinks(
                wData.LinkedPartA,
                wData.DockingPortA,
                wData.LinkedPartB);
            NodeUtilities.SwapLinks(
                wData.LinkedPartB,
                wData.DockingPortB,
                wData.LinkedPartA);

            wData.DockingPortB.SetCollisionIgnores();
            wData.DockingPortA.SetCollisionIgnores();

            NodeUtilities.SpawnStructures(wData.LinkedPartA, nodeA);
            NodeUtilities.SpawnStructures(wData.LinkedPartB, nodeB);


            if (compress)
            {
                NodeUtilities.MovePart(wData.LinkedPartB, offset);
            }



            PartJoint newJoint = PartJoint.Create(
                wData.LinkedPartB,
                wData.LinkedPartA,
                nodeB,
                nodeA,
                AttachModes.STACK);

            wData.LinkedPartB.attachJoint = newJoint;

            SoftExplode(wData.DockingPortA);
            SoftExplode(wData.DockingPortB);
        }
Exemple #2
0
        public void FixedUpdate()
        {
            if (!PistonAnimation.IsPlaying(pistonAnimationName))
            {
                PistonAnimation[pistonAnimationName].speed = 0f;
                PistonAnimation.Play();
            }

            //Is there a diff between the current step and the animation step?
            if (curTime != aniTime)
            {
                //If so...
                var child = part.children[0];

                var offset =
                    part.transform.localPosition
                    - child.transform.localPosition;

                offset.Normalize();

                var diff = 1 + stepSize / (curTime - aniTime);
                offset *= diff;

                var nodeA = NodeUtilities.GetLinkingNode(part, child);
                var nodeB = NodeUtilities.GetLinkingNode(child, part);

                NodeUtilities.DetachPart(child);

                PartJoint newJoint = PartJoint.Create(
                    child,
                    part,
                    nodeB,
                    nodeA,
                    AttachModes.STACK);

                child.attachJoint = newJoint;

                // Move the parts
                NodeUtilities.MovePart(child, offset);

                // Set the animation's normalized time.
                PistonAnimation[pistonAnimationName].normalizedTime = curTime;

                aniTime = curTime;
            }
        }
Exemple #3
0
        private Vector3 GetOffset(WeldingData wData)
        {
            var totalThickness = 0f;
            var objA           = new GameObject();
            var objB           = new GameObject();

            var transformA = objA.transform;
            var transformB = objB.transform;

            transformA.localPosition = wData.DockingPortA.transform.localPosition;
            transformB.localPosition = wData.DockingPortB.transform.localPosition;

            var offset =
                transformA.localPosition - transformB.localPosition;

            offset.Normalize();

            totalThickness += NodeUtilities.GetPartThickness(wData.DockingPortA);
            totalThickness += NodeUtilities.GetPartThickness(wData.DockingPortB);

            offset *= totalThickness;

            return(offset);
        }