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

How to make a opening door using CFrame Lua?

Asked by 10 years ago

I want to create a door that opens via CFraming rather then turning off CanCollide and making the Transparency to 1. My scripting knowledge is too low. Help please.

1 answer

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
10 years ago

Here's an example of swinging a part on its right-side axis to open like a door. It first uses to the offset of the right side and then rotates it based on that CFrame, instead of the center.

It runs by simply putting the script in the part.

local increment = .05 -- best to keep it to a 5-base of 1(0)-base increment

function RunAnimation(p)
    local p = p or script.Parent
    local rightframe = p.CFrame + p.CFrame:vectorToWorldSpace( Vector3.new(1,0,0) * p.Size.X/2 )
    for i = 0, math.pi/2, .05 do
        wait()
        local newframe = rightframe * (CFrame.Angles(0, -i, 0) * CFrame.new(p.Size.X/-2,0,0))
        p.CFrame = newframe 
    end
end

RunAnimation()
Ad

Answer this question