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

How would I rotate parts around a pivot?

Asked by 9 years ago

I personally have very little experience with CFrame, so how would I do this?

0
I found one a question asking the same thing, but I didn't understand it that much. HungryJaffer 1246 — 9y
0
I did it once, but i can't remember exactly how i did it, i think I put one block in the middle of the map to be the center point of movement, and rotated the model using that? Im sorry i don't remember exactly how i did it yogipanda123 120 — 9y

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

If you want to rotate a part around a certain CFrame, you have to put its orientation in terms of that CFrame (its object space) and then change it relatively to make it pivot around that point.

local pivot=CFrame.new()
local new=pivot*CFrame.Angles(0,math.pi/4,0)

Part.CFrame=new:toWorldSpace(pivot:toObjectSpace(Part.CFrame))
Ad
Log in to vote
0
Answered by 9 years ago

One way is to have a part that is welded to the part that you want to move, however, you move the welded part. (I recommend having the size of the part you move to be as small as possible)

Here's what I mean:

local pivot = game.Workspace.PivotPart --Change this to where the PivotPart is
local Part = game.Workspace.Part --Change this to the part you want to move

--Welding...
local W = Instance.new("Weld") --Create a weld
W.Part0 = pivot --Make Part0 the pivot point
W.Part1 = Part --Make Part1 the part you want to move
local CJ = CFrame.new(pivot.Position) --These next three lines are calculating how to offset the part
local C0 = pivot.CFrame:inverse()*CJ --so that the pivot point is at the same location you position
local C1 = Part.CFrame:inverse()*CJ --it. So you don't have to CFrame this part.
W.C0 = C0 --Changing the CFrame of the pivot point
W.C1 = C1 --Changing the CFrame of the actual part
--So now the pivot point is welded to the part and it looks the same as it would in studio
W.Parent = pivot --Finally, assign the Parent of the weld to the pivot point

--Now we can move the part around by changing the CFrame of the Pivot point!

while wait() do --You don't have to have this part, but what it does is it makes the part rotate along the
    pivot.CFrame = pivot.CFrame * CFrame.Angles(0, math.rad(1), 0) --Y axis at 1 radian every 0.03
end --seconds. This is an example, not a requirement.

If you like 1waffle1's answer better, that's fine. But I think my idea would be a bit longer, yet easier to use.

0
This is the solution for unanchored parts. Just welding one part to another part and then rotating that other part will cause the part to rotate around it, preserving its offset. 1waffle1 2908 — 9y
0
Unanchored parts? You mean this doesn't work for anchored parts? I've tried it in the past and it works... lightpower26 399 — 9y

Answer this question