Rotating around somehting else using Tween Service

Im trying to make an animated door, here’s how it looks:

https://gyazo.com/2f2e71d47ac3f832b9d22ad9e4b67826

How would I make it better? Because as you can see it doesn’t work perfectly

The script:

local TS = game:GetService("TweenService")

local button = script.Parent

local door = game.Workspace.DoorModel.Door
local bar = game.Workspace.DoorModel.Bar

local doorCF = door.CFrame

local isOpen = door.IsOpen

----------------------

button.MouseClick:Connect(function(plr)
	
	if isOpen.Value == false then
		
		isOpen.Value = true
	
		local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
		
		local goal = {CFrame = CFrame.new(bar.Position) * CFrame.Angles(0, math.rad(120), 0) * CFrame.new(0, 0, 7.015)}
		
		local tween = TS:Create(door, info, goal)
		
		tween:Play()
		
	else
		
		isOpen.Value = false
		
		local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
		
		local goal = {CFrame = doorCF}
		
		local tween = TS:Create(door, info, goal)
		
		tween:Play()
		
	end
	
end)

Add a part at the point you want the door to rotate around. Add a weld between it and the door. Now Tween the hinge part instead of the door. Make sure the hinge is anchored and the door is unanchored, so the weld will work.

EDIT: That was very confusing. I worded that very poorly. But, the link @InherentBalance shared does basically the same thing, but explains much better.

There’s an article discussing what you’re trying to do.

I’m having one problem with that article, the hinge part, the door isn’t moving with the hinge, I tried adding a weld constraint but didn’t fix it

Edit: Nvm i fixed it, thx for showing me this article! will certainly help me a lot

1 Like