I'm terrible with math, so please help me with this.
Say I have a part, I want to clone it and place the clone on top of the part, but at an angle (x axis).
( So, I'm basically creating an arc of on top of a part. )
local rotation = 15; local part = workspace.Part:clone(); local cf = part.CFrame; part.Parent=workspace; p.CFrame=cf * CFrame.Angles(math.rad(rotation), 0,0) * CFrame.new(0,0,0); -- What do I do here to make it fit smoothly on top of the other part, and to offset by the rotation so there aren't any cracks?
This should be pretty simple. I'm just terrible at math/logic. :P
I hope I got your question right: You want to move the part to the top of another part and THEN rotate it?
In that case, you need the following
-The size of the part and the other part -The other parts CFrame -The angle
Use:
local YDiff = otherpart.Size.y/2 + part.Size.y/2 local angle = 30 part.CFrame = otherpart.CFrame * CFrame.new(0, YDiff, 0) * CFrame.Angles(math.rad(angle), 0, 0)
Explanation:
CFrames are offsets. Normally, you would say a = b * c = c * b
(order of multiplications don't matter). For CFrames the order DOES matter. (Because it has a rotation matrix, and by multiplying matrices the order does matter!)
You have to think in offsets. You first want to move it up to the brick and then rotate it. If you rotate first and THEN move it up, you will see that it will get offsetted in the "direction" you aimed it at.