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

Keeping an objects rotation when moving it with CFrame?

Asked by 5 years ago

Hello,

As from my last post, I have been able to make a script that allows the door that I'm working on to move up and down from the click of a button. The only issue I have now is that upon pressing the button, the door will rotate 90 degrees, making it look weird and out of place.

I've also had a lot of issues with this in the past, yet just scrap the idea as I can never figure out a way to fix this.

01local LeftDoor = script.Parent.Parent.Parent.LeftOfficeDoor
02local RightDoor = script.Parent.Parent.Parent.RightOfficeDoor
03local Sound = script.Parent.Sound
04local debounce = false
05local door = false
06local Rotation = LeftDoor.CFrame - LeftDoor.Position
07 
08script.Parent.ClickDetector.MouseClick:connect(function()
09    if not debounce then debounce = true
10    if not door then door = true
11            Sound.Playing = false
12            Sound.Playing = true
13        for i = 1,14 do
14            LeftDoor.CFrame = CFrame.new(LeftDoor.Position + Vector3.new(0,1,0))
15            wait()
View all 29 lines...

The door works perfectly fine, its just the rotation. I have seen many forms about this, yet the explaining on them is very little and I have no idea where to place them into my script.

If anyone could help, it would be greatly appreciated.

2 answers

Log in to vote
1
Answered by 5 years ago

Try this (may not be the best solution)

01local RunService = game:GetService("RunService")
02local LeftDoor = script.Parent.Parent.Parent.LeftOfficeDoor
03local RightDoor = script.Parent.Parent.Parent.RightOfficeDoor
04local Sound = script.Parent.Sound
05local debounce = false
06local door = false
07local Rotation = LeftDoor.CFrame - LeftDoor.Position
08 
09RunService.RenderStepped:Connect(function()
10    LeftDoor.Orientation = Vector3.new(0,0,0)-- Put the original Orientation of the door in the brackets
11    RightDoor.Orientation = Vector3.new(0,0,0)-- Put the original Orientation of the door in the brackets
12end)
13 
14script.Parent.ClickDetector.MouseClick:connect(function()
15    if not debounce then debounce = true
View all 35 lines...
0
I had just done this before you posted it and it works, so thanks anyway! DiamondRules01 56 — 5y
0
aw thanks for excepting my answer anyways :D Have a good day! NarwhalAndMe 141 — 5y
0
oh darnit i did the thing wrong though :/ NarwhalAndMe 141 — 5y
0
oh darnit i did the thing wrong though :/ NarwhalAndMe 141 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Aha, didn't really expect it to be this easy. I fixed it by changing the orientation in the script each time.

01local LeftDoor = script.Parent.Parent.Parent.LeftOfficeDoor
02local RightDoor = script.Parent.Parent.Parent.RightOfficeDoor
03local Sound = script.Parent.Sound
04local debounce = false
05local door = false
06local Rotation = LeftDoor.CFrame - LeftDoor.Position
07 
08script.Parent.ClickDetector.MouseClick:connect(function()
09    if not debounce then debounce = true
10    if not door then door = true
11            Sound.Playing = false
12            Sound.Playing = true
13        for i = 1,14 do
14            LeftDoor.Orientation = Vector3.new(0, -90, 0)
15            LeftDoor.CFrame = CFrame.new(LeftDoor.Position + Vector3.new(0,1,0))
View all 33 lines...

Answer this question