Moving a part to another part based on attachment

Basically part1 has attachment in it and i want to move part1 to a attachment in part2 by part1’s attachment, how would i go about doing this?

2 Likes

Its not direct to part what you are saying but you can adjust the cframe

while true do
wait(1)
for i= 1, 200 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, 0.3)
wait()
end
wait(1)
for i= 1, 200 do
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0, -0.3)
wait()
end
end

i am not looking to adjust the cframe, i want to move part1 to part2’s attachment cframe by part1’s attachment cframe

I believe you are asking to offset a part movement CFrame via an attachment?

For @DylTheDeveloperX I believe we can do better by being exact by using mathsss. For this you can use the attachment formula for the world CFrame:

attachmentWorldCFrame = part1.CFrame * attachment.CFrame --how attachment.WorldCFrame is calculated
--inverse both sides by attachment.CFrame
attachmentWorldCFrame * attachment.CFrame:Inverse() = part1.CFrame -- inverse the attachment CFrame to get the part1 CFrame

for your case attachmentWorldCFrame is the one thats being changed to attachment2 CFrame and attachment.CFrame still remains attachment1 so here is what the end result should be. Try it out? I hope its correct.

part1.CFrame = attachment2.WorldCFrame * attachment1.CFrame:Inverse()
14 Likes

@dthecoolest I think that should work.

your solution worked, thanks man!