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

Make a door rotate backwards w/ CFrame?

Asked by 5 years ago

I was following a tutorial regarding door rotation but also wanted to know how to make it rotate back into place once moved.

01local hinge = script.Parent:WaitForChild("Hinge")
02local door = script.Parent:WaitForChild("Door")
03 
04local HINGEPOS = hinge.Position
05 
06for i = 1, 15 do
07    wait()
08    door.CFrame = CFrame.new(HINGEPOS) * CFrame.Angles(0, math.rad(i*6), 0) * CFrame.new(0, 0, 2.25)   
09end
10wait(1)
11for i = 1, 15 do
12    wait()
13    door.CFrame = CFrame.new(HINGEPOS) * CFrame.Angles(0, math.rad(i*-6), 0) * CFrame.new(0, 0, 2.25)  
14end

I couldn't find comments on the video asking nor any mention of it in the video itself.

1 answer

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

do the same thing but make the angle negative

01local hinge = script.Parent:WaitForChild("Hinge")
02local door = script.Parent:WaitForChild("Door")
03 
04local HINGEPOS = hinge.Position
05 
06for i = 1, 15 do
07    wait()
08    door.CFrame = CFrame.new(HINGEPOS) --puts door at the hinge's position
09                * CFrame.Angles(0, -math.rad(i*6), 0--rotates door
10                * CFrame.new(0, 0, 2.25--shifts door forward
11end
0
This works but how would I go about turning it to its original position? Utter_Incompetence 856 — 5y
0
In the loop above you moved the door backwards by rotating the door with negative angles. To go back to where you were before, do the same for loop with a positive angle like in your original post. royaltoe 5144 — 5y
0
So same way you did it in the original post. royaltoe 5144 — 5y
0
hi did everything turn out alright? royaltoe 5144 — 5y
View all comments (2 more)
0
post was accepted then unaccepted so I'm worried I did something wrong royaltoe 5144 — 5y
0
Ah sorry, scriptinghelpers doesn't notify me on replies for some reason! Utter_Incompetence 856 — 5y
Ad

Answer this question