I have been trying to make my own CFrame swing doors lately, and I've been running into some problems, like the door swings open, but it doesn't swing back in the right way, is there a way to calculate the correct numbers and angles to put into the CFrames? If not, can you at least answer with some tips on how to make the CFrames work right? Here's what I've got:
local Door = script.Parent local DoorFrame = Door.Parent local CD1 = Door.CD --I am still not sure about the numbers in here, the dimensions of the door are (4, 6, 0.4) function Open1() if Door.InUse.Value then Door.InUse.Value = true for i = 1, 18 do Door.CFrame = Door.CFrame * CFrame.new(0, 0, 0.21) * CFrame.fromEulerAnglesXYZ(0, 0.1, 0) wait(0.01) end wait(1.5) for i = 1, 18 do Door.CFrame = Door.CFrame * CFrame.new(0.002, 0, -0.22) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0) wait(0.01) end Door.InUse.Value = false end end CD1.MouseClick:connect(Open1)
Here's how you rotate a part around a point (or in your case, a door).
part.CFrame = origin*rotation*(origin:inverse()*part.CFrame)
origin
is the point (CFrame, not Vector3) you're rotating around, and rotation
is the CFrame you're rotating by.
Added to your code, it will look like this:
local Door = script.Parent local origin = CFrame.new(Door.Position - Vector3.new(Door.Size.X/2,0,0)) --You're probably going to need to fix the origin yourself local DoorFrame = Door.Parent local CD1 = Door.CD function Open1() if not Door.InUse.Value then Door.InUse.Value = true for i = 1, 18 do Door.CFrame = origin * CFrame.Angles(0,math.rad(90/18),0) * (origin:inverse()*Door.CFrame) wait(0.01) end wait(1.5) for i = 1, 18 do Door.CFrame = origin * CFrame.Angles(0,-math.rad(90/18),0) * (origin:inverse()*Door.CFrame) wait(0.01) end Door.InUse.Value = false end end CD1.MouseClick:connect(Open1)