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 4 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,

script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0, 0) * CFrame.fromEulerAnglesXYZ(0, 90, 0)
wait(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,

function doorOpened()
    local state = script.Parent.Parent.DoorState
    local hinge = script.Parent.Parent.DoorHinge
    local doorknob = script.Parent.Parent.DoorKnobBase
    local Model = script.Parent.Parent

    if state.Value == false then 
          local newCFrame = CFrame.Angles(0,math.deg(5),0)
          hinge.CFrame = newCFrame
          wait(0.1)
          doorknob.CFrame = CFrame.Angles(0,0,math.deg(2.4))
          wait(0.2)
          doorknob.CFrame = CFrame.Angles(0,0,math.deg(0))
          state.Value = true
    else
          local oldCFrame = CFrame.Angles(0,math.deg(90),0)
          hinge.CFrame = oldCFrame
          wait(0.1)
          doorknob.CFrame = CFrame.Angles(0,0,math.deg(2.4))
          wait(0.2)
          doorknob.CFrame = CFrame.Angles(0,0,math.deg(0))
          state.Value = false
      end
end


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.

1
CFrame * CFrame.Angles, not just CFrame.Angles DeceptiveCaster 3761 — 4y
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 — 4y

Answer this question