How to swing open doors using CFrames?

I’ve been browsing the internet for possible solutions, though everyone I’ve used went horribly wrong.

I’m making a door system, and I have like 1000 doors. I’ve had luck with CFrame tweeting, though this is what happens.

https://streamable.com/eglcto

local PrimaryPart = doorObj:FindFirstChild("Door1").PrimaryPart
TweenService:Create(
		PrimaryPart, 
		TweenInfo.new(), 
		{CFrame = PrimaryPart.CFrame * CFrame.Angles(0, 20, 0)}
	):Play()

Also, keep in mind, it has multiple in the door1 model, so any feedback/help would be appreciated.

CFrame.Angles does not Accept Degree’s and uses another unit of measurement called Radians, if you want to convert Degrees to Radians, use math.rad(x) or the formula x*(pi/180)

You may need to set a slight offset to the Door to get the Desired effect, or Rotate a type of Hinge, they are very basic, but can get you the desired effect.

I still get the same results with using math.rad()

Still need help with this, and I’m out of ideas on how I get this to work using CFrames and tweens

So you want for your door to open with TweenService?

ah yes, my favourite service, TweetingService

1 Like

You will have to make another part, that will be… door’s holder, I think? (sorry for engrish)
Next, you will just have to

TweenService:Create(
	PrimaryPart, 
	TweenInfo.new(), 
	{CFrame = doorHolder.CFrame * CFrame.Angles(0, math.rad(20), 0)}
):Play()

The “holder” should be on the side of the door in which direction you want for it to open/close.
Note: using math.rad() IS necessary. As @DasKairo said, CFrame.Angles uses radians, not degrees. Also the primary part should be right on the holder.

As Cairo said, Angles should use radians or the formula.

Even if you do that, you still rotating the Door from its center pivot, you need to offset the pivot to rotate, based on the size of the door, an example:

-- offset the pivot of rotation
local pivotOffset = Vector3.new(door.Size.X / 2, -door.Size.Y / 2, 0)

-- the rads to sum
local rotation = CFrame.Angles(math.rad(0), math.rad(75), math.rad(0))

-- create the rotation CFrame
local newCFrame = door.CFrame * CFrame.new(pivotOffset) * rotation * CFrame.new(-pivotOffset)

-- apply rotation
task.wait(3)
door.CFrame = newCFrame

This is 75º on radians to open the door:

3 Likes

But… because Im bad at “math” I prefer to being practical and use a physical pivot, and the Door is welded by a WeldConstraint to the pivot, and only tween the pivot to get the effect:

local doorPivot = script.Parent:WaitForChild("Pivot")
local rotation = doorPivot.CFrame * CFrame.Angles(math.rad(0), math.rad(75), math.rad(0))

task.wait(5)
game:GetService("TweenService"):Create(doorPivot, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, -1, true), {CFrame = rotation}):Play()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.