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

How does rotation using *CFrame.Angles() work?

Asked by 7 years ago

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 :/

1 answer

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

I think I understand your problem.

When moving something along an axis, things are simple. In Roblox, Y is up. However with rotating, this is not the case.

Why?

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.

Than why does it move all the axes when I do this?

When multiplying CFrames, the start rotation of the object stays the same. To make it simple, this makes the rotation Local apart from global.

How do I make the rotation 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 wasn't sure if you could multiply Vector3s by CFrames, even though I'm pretty sure you can, I just made the Vector into a CFrame to be safe.

I hope I helped!

Good Luck!

If I helped please don't forget to accept my answer.
0
The code that you gave me didnt quite do what I needed, but your comment on sticking a rod into a ball gave me a lead on this question. Thanks! quannguyen9 15 — 7y
Ad

Answer this question