who knows how I can script this? I want the edge of the first and second to be connected
with using math.sin() and math.cos()
Hello, judging off of your example, I assume you’re looking for how to rotate a part along an origin (in this case if around a part that is a square, the origin is the corner). This can be accomplished with some pretty basic CFrame maths.
How it works
Basically, you have a point at a position representing the origin and a part to be rotated along the point. The first thing you need is the original transformation from the origin’s base CFrame (local oCFrame = CFrame.new(originR)
) to the part’s CFrame. This can be done by using the CFrame:ToObjectSpace()
method (local originToPartTransform = oCFrame:ToObjectSpace(part.CFrame)
). This makes part.CFrame
equivalent to oCFrame*originToPartTransform
. Now that we have the transformation from the base origin to the part’s CFrame, we can now get the part’s new relative CFrame when rotating the origin CFrame! The origin CFrame can now be rotated by: oCFrame *= CFrame.Angles(x,y,z)
. Once rotated, we can get the final CFrame of the part by getting oCFrame*originToPartTransform
. And there we have it: a rotation of a part (or CFrame) based on an origin point!
The Code
function rotateByOrigin(part: Part,rotation: CFrame,origin: Vector3)
local oCFrame = CFrame.new(originR)
local originToPartTransform = oCFrame:ToObjectSpace(part.CFrame)
oCFrame *= rotation
part.CFrame = oCFrame*originToPartTransform
end
-- Example call
rotateByOrigin(targetPart,CFrame.Angles(0,math.rad(30),0),originPosition)
Hope this all helps! Let me know if you have any questions.