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); }
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; } }