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

How do I change the rotation of this model using ":GetPrimaryPartCFrame" for a door?

Asked by 6 years ago
local Door = script.Parent.Parent.Parent
local mainPart = script.Parent.Parent.Parent.Union
local Handle = script.Parent



local openDoor = false
Handle.ClickDetector.MouseClick:Connect(function()
    if openDoor == false then
        for i = 1, 13 do
            Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame(Vector3.new(-6.152, 3, -8.748)) * CFrame.Angles(0,math.rad(-i),0))
            wait(0.01)
        end
        openDoor = true
    end
end)

The problem I'm having is when I click the handle it rotates the door, but I also want it to move as well, so the door looks realistic and isn't just rotated in the middle of the doorway.

0
GetPrimaryPartCFrame() returns the CFrame of the PrimaryPart in the model. (The same as Model.PrimaryPart.CFrame, If you've set a primaryPart.) you've placed a Vector3.new() inside of it, that won't do a thing. RubenKan 3615 — 6y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

The easiest way to achieve this is to set the PrimaryPart of the door to a part that will act as the hinge of the door. You can do this by creating an invisible part inside of the door model that is positioned at the edge of the door, and then setting the PrimaryPart to that invisible part. As the door rotates relative to the PrimaryPart when using SetPrimaryPartCFrame, the rest of the door will rotate relative to the hinge part, creating the opening effect.

If you called the part that you wanted to rotate it relative to Hinge, you could put this on the second line of your script:

Door.PrimaryPart = Door:FindFirstChild("Hinge",true)

Otherwise, you can just set the PrimaryPart manually in the properties window.

Ad

Answer this question