Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can someonel help me with CFraming door rotations?

Asked by
Xetrax 85
9 years ago

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)
0
Post what you have. 2eggnog 981 — 9y
0
The script? Xetrax 85 — 9y
0
Yep. 2eggnog 981 — 9y
0
I have no idea what I'm doing, as I'm new here... but there it is! Xetrax 85 — 9y
0
AHA, finally found out what code break does! Xetrax 85 — 9y

1 answer

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
9 years ago

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)
0
Thanks, also, I recently joined the SH group and posted a question on the wall... but your answer will really help me with my future doors, Thanks! Xetrax 85 — 9y
0
One question... how do I do that exactly... as I said... I'm new here... Xetrax 85 — 9y
0
Thanks again! Xetrax 85 — 9y
0
NP 2eggnog 981 — 9y
Ad

Answer this question