Jump to content

transform.localPosition of a node instead of a part


Recommended Posts

I have this function based on the one in the Konstruction mod:

private Vector3 GetOffset(WeldingData wData)
{
    //var nodeA = WeldingNodeUtilities.GetLinkingNode(wData.LinkedPartA, wData.part0);
    //var nodeB = WeldingNodeUtilities.GetLinkingNode(wData.LinkedPartB, wData.part0);

    //Vector3 offset = nodeA.position - nodeB.position;   // offset in wrong direction, depends an an angle of the craft? 
    //Vector3 offset2 = nodeA.nodeTransform.localPosition - nodeB.nodeTransform.localPosition;   // // nulref 

    // works for a stack of simple simmetrical parts (tanks)
    Vector3 offset3 = wData.LinkedPartA.transform.localPosition - wData.LinkedPartB.transform.localPosition;
    offset3.Normalize();
    offset3 *= WeldingNodeUtilities.GetPartThickness(wData.part0);
    return offset3;
}

// .....

partB.transform.position += offset;

Idea there pretty simple, we take vector (direction) of an future shift as difference of positions, normalize it, and then give it the desired length.

offset3 use linked parts for that difference, while mathematically it's enough (and make more sense) to use corresponding nodes of the part0 for that difference. Also this way it will not be dependent on models of linked parts. (I consider .transform.localPosition as some kind of center of a part).

I have tried to use nodes (offset, offset2), but it is failed. How to switch to using nodes?  

 

 

Link to comment
Share on other sites

the solution is 
 

Vector3 offset =
    nodeA.owner.transform.rotation * nodeA.position + nodeA.owner.transform.position -
    nodeB.owner.transform.rotation * nodeB.position + nodeB.owner.transform.position;

or simplified:

Vector3 offset = part.transform.rotation * (nodeA.position - nodeB.position);

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...