How do I translate a list of CFrames by the difference in rotation and Position of two duplicates of the same model

So I have two models, one is a duplicate of the other that has been moved and rotated. I have CFrameValues as well that are based on the original unmoved/unrotated model. I want to find the difference in position and rotation in world space, between a part from the original model and the same part from the rotated/moved model. And then apply that difference (still in world space) to all my CFrameValues.

I have tried several different methods but can’t seem to achieve this effect as I’m not the most experienced with CFrames.

I’m pretty sure you can subtract CFrame.Position and CFrame.Rotation together to get the difference

It errors when subtracting the rotations

According to a post I just found, to get the offset of two CFrames, you need to multiply c1 with c2:Inverse(), where c1 and c2 are both CFrames. I think this could also work for rotation, but you’d have to check

You can give it a read if you want, I honestly found it interesting

1 Like
print ("Base: ", baseModel.PrimaryPart.CFrame)
print ("Target: ", targetModel.PrimaryPart.CFrame)
local offset = baseModel.PrimaryPart.CFrame:Inverse() * targetModel.PrimaryPart.CFrame
print("Offset: ", offset)

This is what it’s printing, which doesn’t quite look right

Hmmm, is your model’s PrimaryPart a BasePart? if yes you can directly subtract position and rotation. I honestly have no idea. I think you could also go for CFrame.new(x1 - x2, ...)

It’s a MeshPart. I also already tried that before and it was glitchy when it came to my CFrameValues, they weren’t correct. Although I tried adding onto what we did before and it seems like it actually worked for translating it, so I’m going to try applying it to all my CFrameValues and see if it works.

local a = baseModel.PrimaryPart.CFrame
local b = targetModel.PrimaryPart.CFrame
print ("Base: ", a)
print ("Target: ", b)
local offset = a:Inverse() * b
print("Offset: ", offset)
local newCFrame = a * offset
print("Translated: ", newCFrame)

So I basically used the code above, but to edit my CFrame values I got the offset between their default CFrame value and their other CFrame values for the keyframes. I then multiplied that new offset by the new default CFrame that was translated with the code above. And that worked flawlessly.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.