Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Make a door rotate backwards w/ CFrame?

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

local hinge = script.Parent:WaitForChild("Hinge")
local door = script.Parent:WaitForChild("Door")

local HINGEPOS = hinge.Position

for i = 1, 15 do
	wait()
	door.CFrame = CFrame.new(HINGEPOS) * CFrame.Angles(0, math.rad(i*6), 0) * CFrame.new(0, 0, 2.25)	
end
wait(1)
for i = 1, 15 do
	wait()
	door.CFrame = CFrame.new(HINGEPOS) * CFrame.Angles(0, math.rad(i*-6), 0) * CFrame.new(0, 0, 2.25)	
end

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

1 answer

✓ Accepted answer

do the same thing but make the angle negative

local hinge = script.Parent:WaitForChild("Hinge")
local door = script.Parent:WaitForChild("Door")

local HINGEPOS = hinge.Position

for i = 1, 15 do
	wait()
	door.CFrame = CFrame.new(HINGEPOS) --puts door at the hinge's position 
				* CFrame.Angles(0, -math.rad(i*6), 0)  --rotates door
				* CFrame.new(0, 0, 2.25)  --shifts door forward 
end

6 comments

0

This works but how would I go about turning it to its original position?

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.

0

So same way you did it in the original post.

0

hi did everything turn out alright?

0

post was accepted then unaccepted so I'm worried I did something wrong

0

Ah sorry, scriptinghelpers doesn't notify me on replies for some reason!

This discussion is preserved as it was. New answers, comments, and votes are closed.