Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would you rotate a part based on its position from another part?

I'm generating parts evenly around the perimeter of a cylinder, which I do with this.

local function GenerateParts(Amount)
	local Theta = math.pi * 2 / Amount
	for i = 1,Amount do
		local Angle = Theta * i
		local X = Radius * math.cos(Angle)
		local Y = Radius * math.sin(Angle)
		local Z = Base.Position.Z
		local newPart = PartTemplate:Clone()
		PartTemplate.Parent = Base.Parent
		PartTemplate.CFrame = CFrame.new(X,Y,Z) * CFrame.Angles(0,math.pi/2,0)
	end
end

Where I'm stuck is generating the parts so each would be rotated with one corner facing the cylinder's Z, and one facing outward. It's probably less complicated than I'm making it, but does anyone have a solution for this?

1 answer

Forgot I posted this. The solution was more simple than I made it out to be; set the focus of the CFrame before adjusting the angle.

This discussion is preserved as it was. New answers, comments, and votes are closed.