I want to store the difference between two parts' CFrames to later use Part:ToWorldSpace() on one object to set another's position and orientation relative to it. Would this even be possible? To be a little more clear, basically this is what I want to do:

--Module Script for setup

local differences = {}
for i,p in pairs(script.Parent:GetDescendants()) do
	if p:IsA("BasePart") then
		differences[i] = {p,(CFrame Difference between this part and some Anchor Part)}
	end
end


--Some other script

for _,v in pairs(differences) do
	v[1].CFrame = AnchorPart.CFrame:ToWorldSpace(difference)
end

6 comments

0

You can use Object.CFrame:ToObjectSpace(CFrame2). Which gives the difference in CFrame of CFrame2 from Object.

0

This difference is known as an offset by the way

0

Could you provide a code sample or API reference to using ToObjectSpace()?

0

https://developer.roblox.com/en-us/api-reference/datatype/CFrame; scroll down to functions. The Wiki doesn't explain it too well.

0

Part.CFrame:ToObjectSpace(Part2.CFrame) returns the difference in position between Part and Part2, while considering Part as the relative origin.

0

That works very well! Thank you!