How do I rotate a door around a custom Pivot Point rather than the center?

Issue:

I have a microwave door that I am trying to open at that specific Pivot Point (in the image). I wrote a code but it is making the door revolve around the center of its mass rather than the Pivot Point I want it to. How do I modify the pivot point in the script so that it rotates around my hinge point?

Code:

Code
    local microwaveDoor = Microwave:FindFirstChild("Door")
    if microwaveDoor then
        local TweenService = game:GetService("TweenService")
        local openDoorInfo = TweenInfo.new(
            0.8,           -- Duration (seconds)
            Enum.EasingStyle.Quad,  -- Easing style
            Enum.EasingDirection.Out -- Easing direction
        )
        
        local openDoorGoal = {
            CFrame = microwaveDoor.CFrame * CFrame.Angles(0, math.rad(-90), 0)
        }
        
        local openDoorTween = TweenService:Create(microwaveDoor, openDoorInfo, openDoorGoal)
        openDoorTween:Play()
    end

make a part where your pivot is and mess around with the c0 settings until it goes to the left thats all i know of

Unfortunately, you can’t tween a BasePart around a pivot because the tween will take the shortest path to reach the target CFrame which will ignore the rotation around the pivot, defeating the entire purpose.

Because you’re using TweenService to move the door, rather than directly tween the door’s CFrame, you can instead tween a CFrame value and then use that value to update the door’s CFrame every heartbeat.

The update function would look something like this:

function onHeartbeat()
	microwaveDoor:PivotTo(CFrame.new(microwaveDoor:GetPivot().Position) * CFrameValue.Value)
end

RunService.Heartbeat:Connect(onHeartbeat)

When tweening the CFrame value, you only need to tween the rotation.

After the tween has ended, you should additionally call :Disconnect() on the connection created by RunService.Heartbeat to avoid any memory leaks.

1 Like

Anyway the easiest way to do this is literally like what the first person said, create a invisible anchored part at the hinge point you want your door to swing from; now you can either weld your entire microwave door to that hinge and the microwave door be unanchored and tween the hinge itself in rotation or do fancy math cframe.new(hingepos) * angle * cframe.new(microwaveoffset something)

make sure the angle is done in the middle of the two else it wont work;
hope this helped; consider looking at how to make a piggy door on youtube or any door in roblox it might help!!

1 Like