Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Ad

Answer this question