Combining Models with respect to their attachment CFrames

Hey There!
I’m trying to move one model to another model so that the CFrame of the first Model’s attachment matches the CFrame of the second model’s attachment.

(Here I’m moving the red Model with respect to the blue model’s attachment)

Before:

After:
image

Video To Explain:
https://gyazo.com/70ed29211f7b28c71d845cacd8ea1a0f

I know how to do this with Position and Orientation values with BaseParts, however I’m not sure how to make this happen for models with CFrame.

Thanks for Trying!

2 Likes

This is very similar to how welds work

Basically, you want a cframe so that:

cframe1 * offset1 = cframe2 * offset2

Where offset is the local cframe of the attachment

To solve for cframe2, just multiply it by the inverse of offset2 like this:

cframe2 = cframe1 * offset1 * offset2:Inverse()

You should be able to just do setprimarypartcframe or some other similar function to set cframe2

2 Likes

let me work it out and get back to you! Thanks for replying btw :smiley:

1 Like

Works like a charm! I owe you one dude!