CFrame.Angles rotates and moves a part, what could I do to only rotate it?
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,
1 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new( 0 , 0 , 0 ) * CFrame.fromEulerAnglesXYZ( 0 , 90 , 0 ) |
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,
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 |
07 | if state.Value = = false then |
08 | local newCFrame = CFrame.Angles( 0 ,math.deg( 5 ), 0 ) |
09 | hinge.CFrame = newCFrame |
11 | doorknob.CFrame = CFrame.Angles( 0 , 0 ,math.deg( 2.4 )) |
13 | doorknob.CFrame = CFrame.Angles( 0 , 0 ,math.deg( 0 )) |
16 | local oldCFrame = CFrame.Angles( 0 ,math.deg( 90 ), 0 ) |
17 | hinge.CFrame = oldCFrame |
19 | doorknob.CFrame = CFrame.Angles( 0 , 0 ,math.deg( 2.4 )) |
21 | doorknob.CFrame = CFrame.Angles( 0 , 0 ,math.deg( 0 )) |
27 | script.Parent.ClickDetector.MouseClick:Connect(doorOpened) |
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.