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

CFrame.Angles rotates and moves a part, what could I do to only rotate it?

Asked by 5 years ago

I am attempting to make a door that swings open upon a user clicking it. I had already dabbled in CFrame, and rotations, so I had a basic idea of what I was doing. I did get to where I needed to, the door DOES rotate as I need it to, the problem is, it also changes the position of the door, moving it off into the ground. I have tried a few different methods, the main one being this,

1script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0, 0) * CFrame.fromEulerAnglesXYZ(0, 90, 0)
2wait(0.5)

This one only changed the rotation like I wanted, but it only added onto the rotation, rather than snapping it to a certain orientation. [Basically, if the orientation was (0,90,0), it would make it (0,180,0)]

So, I ultimately settled with this,

01function doorOpened()
02    local state = script.Parent.Parent.DoorState
03    local hinge = script.Parent.Parent.DoorHinge
04    local doorknob = script.Parent.Parent.DoorKnobBase
05    local Model = script.Parent.Parent
06 
07    if state.Value == false then
08          local newCFrame = CFrame.Angles(0,math.deg(5),0)
09          hinge.CFrame = newCFrame
10          wait(0.1)
11          doorknob.CFrame = CFrame.Angles(0,0,math.deg(2.4))
12          wait(0.2)
13          doorknob.CFrame = CFrame.Angles(0,0,math.deg(0))
14          state.Value = true
15    else
View all 27 lines...

I read multiple CFrame guides specifically for rotation, and got the rotation bit from it. Most guides recommended the use of "CFrame.Angles", but I don't think it's helping. If there's a better way to snap a part into a specific rotation spot, please let me know.

The door consists of multiple parts that are all unanchored and held together with WeldConstraints [minus the main hinge, which is anchored and hosts most of the constraints]. The script itself is inside a small part with a click detector.

Scripting is not my forte, I don't understand the entire system very well. If you could include an explanation as to why my script doesn't work, that would be fantastic. Thank you.

1
CFrame * CFrame.Angles, not just CFrame.Angles DeceptiveCaster 3761 — 5y
0
That does work, but it works like the original script I had. It multiplies the current rotation by whatever I have set to, rather than snapping to a specific rotation setting. Thank you for clarifying what I was doing wrong though. flamethower2002 50 — 5y

Answer this question