Creating Motor6Ds and properly aligning the parts with scripts?

Hello!

I was wondering how I would create Motor6Ds with scripts for rotating item previews. The problem is that when unanchoring the parts, they all go to the centre of Part0 which is the bounding box, and I am not sure how to fix that.

Original thickness (target thickness, it’s actually 2 parts)

Thickness after Motor6Ds are created, the 2 wall parts are put into the same place:

Script:

for i,v in pairs(workspace.Wall:GetChildren()) do
	if v:IsA('BasePart') then
		if v.Name ~= 'BoundingBox' then
			local M6D = Instance.new('Motor6D', v.Parent.BoundingBox)
			M6D.Part0 = v.Parent.BoundingBox
			M6D.Part1 = v
			v.Anchored = false
		end
	end
end

Hierarchy: Capture d’écran, le 2020-10-24 à 14.57.13

Thanks in advance for the help!

You need to set the C0 and C1 values of each weld so they are properly offset from one another. There are good plugins that do it automatically, like:

https://www.roblox.com/library/1274343708/RigEdit-Lite#

To do it via scripting, you’d have to get the relative object space of each part from the bounding box, by doing something like this:

M6D.C0 = v.CFrame:ToObjectSpace(v.Parent.BoundingBox.CFrame)

You’ll have to play around with that line of code, maybe flip the cframe’s to get it right, but that’s the general idea.

2 Likes

It worked, thanks so much for the help! I’ve been having the issue for awhile, glad to finally have it solved haha.

1 Like

can you help me too? i have this problem do you have a solution (as he said to mess with the values a bit)