Rotating a part around a pivot

I want to rotate a part let’s say 90 degrees around another part that acts as a pivot.

I found this post on the issue: How to rotate a part around a point while retaining the orientation of the part? though this person is trying to do something else they said in their post how to do what I want to do, just rotate the part around the pivot, and they said this: Object.CFrame = Point * Rotation * Offset.. now I tried to do this, but I don’t think I did it right so if someone could explain how to do it that is what I am looking for.

This is how I did it:

c.CFrame = CFrame.new(anchor.Position * 90 * math.sqrt(math.pow((c.Position.X-anchor.Position.X),2)+math.pow((c.Position.Y-anchor.Position.Y),2)+math.pow((c.Position.Z-anchor.Position.Z),2)))

See if this helps:

I tried what it said in the post but it didn’t change anything. Sorry, I don’t really understand how CFrames work.
This is the new code:

local pivot = anchor.Position
		
local newpivot = CFrame.new(pivot) 
local offset = newpivot:toObjectSpace(c.CFrame) 
newpivot = newpivot * CFrame.Angles(0, anchor.Orientation.X, 0) 
c.CFrame = newpivot * offset 

change anchor.orientation.X to math.rad(90)

1 Like

Thanks! I got it to work, I just changed it to use rad, and also I was supposed to be using the Y rotation anyways :slight_smile:

A little late to the party, but I was having this issue and thought I’d share my method for future readers.

In my situation, I just needed this lever to smoothly move down when the player clicked it:
image

I created another part and positioned it at the very bottom of the lever, and had the script rotate that part instead. My script all stayed the same besides specifying what part I was rotating.

2 Likes