How do I make this door's tween rotate counterclockwise?

I have created a pair of swinging doors for my game. I have previously used a SetPrimaryPartCFrame loop to open and close these doors, but later became dissatisfied with the ugly animation that this method provides. I have converted these doors to use a tween to smoothly open and close the door, but have run into problems regarding the behavior of the door.

I intend for both of the doors to open outwards, as real life doors do. But the tween causes the left door to rotate clockwise, which causes the door to phase through walls positioned on the sides of the door. Here is a video demonstration:

The behavior showcased in the video is undesired. Here is a simplified version of the script that runs the door, which follows the door concept in the article CFrame Math Operations.

local TweenInInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0)

ClickDetector.MouseClick:Connect(function()
	if open == false then
		open = true
		local hingeLeftTween = TweenService:Create(hingeLeft, TweenInInfo, {Orientation = Vector3.new(0, 135, 0)})
		local hingeRightTween = TweenService:Create(hingeRight, TweenInInfo, {Orientation = Vector3.new(0, 45, 0)})
		hingeLeftTween:Play()
		hingeRightTween:Play()
	elseif open == true then
		open = false
		local hingeLeftTween = TweenService:Create(hingeLeft, TweenInInfo, {Orientation = Vector3.new(0, -90, 0)})
		local hingeRightTween = TweenService:Create(hingeRight, TweenInInfo, {Orientation = Vector3.new(0, -90, 0)})
		hingeLeftTween:Play()
		hingeRightTween:Play()
	end
end)

for _,v in pairs(doorLeft:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Hinge" then
		local offset = hingeLeft.CFrame:Inverse() * v.CFrame
		game:GetService("RunService").Heartbeat:Connect(function(dt)
			v.CFrame = hingeLeft.CFrame * offset
		end)
	end
end

for _,v in pairs(doorRight:GetChildren()) do
	if v:IsA("BasePart") and v.Name ~= "Hinge" then
		local offset = hingeRight.CFrame:Inverse() * v.CFrame
		game:GetService("RunService").Heartbeat:Connect(function(dt)
			v.CFrame = hingeRight.CFrame * offset
		end)
	end
end

Is there a way to make the left door rotate properly through a tween, or other methods? Thanks!

1 Like

maybe the orientation of that to the opposite of the RightTween will work?

local hingeLeftTween = TweenService:Create(hingeLeft, TweenInInfo, {Orientation = Vector3.new(0, -45, 0)})

I have found a simple fix to the problem. By changing the starting orientation of the left door to that of Y = 180 this tween allows for the left door to swing open properly.

local hingeLeftTween = TweenService:Create(hingeLeft, TweenInInfo, {Orientation = Vector3.new(0, 45, 0)})

Thanks for the help!

1 Like