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 7 years ago
01local Door = script.Parent.Parent.Parent
02local mainPart = script.Parent.Parent.Parent.Union
03local Handle = script.Parent
04 
05 
06 
07local openDoor = false
08Handle.ClickDetector.MouseClick:Connect(function()
09    if openDoor == false then
10        for i = 1, 13 do
11            Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame(Vector3.new(-6.152, 3, -8.748)) * CFrame.Angles(0,math.rad(-i),0))
12            wait(0.01)
13        end
14        openDoor = true
15    end
16end)

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 — 7y

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 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:

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

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

Ad

Answer this question