So I've been trying to make a script that rotates a ring into a perfectly flat, horizontal position when a button is pressed, but i don't think I understand how rotation works. For example, when I apply this line of code:
while true do wait() script.Parent.CFrame = script.Parent.CFrame * CFrame.Angles(0,math.rad(math.pi*2),0) end
It rotates the ring along the X- Axis by ~ 6.283 each pass ( approximately pi*2), but this only works when the ring starts at a rotation of X:90 Y:0 Z:90. If i rotate it to some weird rotation, say, X:114.838 Y:58.825 Z:50.398, all three coordinates are altered when the script runs, instead of just the X coordinate as seen earlier. Can someone explain why this happens?
Also, when running the script at rotation X:90 Y:0 Z:90, the Y coordinate fluctuates between 0 and -0. Not sure if this is significant, but I thought it'd be worth mentioning.
I have read the ROBLOX Wiki page on CFrame, but I still don't quite understand it :/
When moving something along an axis, things are simple. In Roblox, Y is up. However with rotating, this is not the case.
Think of it like this. Imagine we have a ball. When we rotate it along the Y axis in Roblox, we're actually sticking an imaginary pole through the ball's Y axis. This is same for the X and Z axes as well.
When multiplying CFrames, the start rotation of the object stays the same. To make it simple, this makes the rotation Local apart from global.
Instead of multiplying the CFrame by another CFrame, multiply the position by the CFrame.
while true do wait() script.Parent.CFrame = CFrame.new(script.Parent.Position) * CFrame.Angles(0,math.rad(math.pi*2),0) end
I hope I helped!
Good Luck!