So I have a bug thing where if i try rotating parts and then CFrame-ing the position, the rotations get undone, and if I try CFrame-ing the position then try rotating the parts all go ontop of eachother. I think this is due to me using Vector3 for Rotations, so how would I use CFrame to rotate somthing?
I know you can do like Part.CFrame=CFrame.new((Position),(rotation)) but that doest set rotation, it adds it.
I know this is a little confuziling so talk to me in chat if u have any questions.
CFrame.Angles
I believe the function you're looking for is CFrame.Angles
. Using this function will add (or set) the rotation of a given CFrame
matrices.
"How does this work?"
Well, CFrame.Angles
works in radians
. Radians are convenient units of degrees that are "equal to an angle at the center of a circle whose arc is equal in length to the radius". Basically meaning we're working with degrees (which is obvious, since we're dealing with rotation).
PIE!
A great standpoint for measuring the rotation of an angle, would be one of the most famous numbers of all time, pi
. In case you didn't know, pi is actually measured in radians. And because we know pi is half a circle (or half a rotation), we can easily manipulate this number to get accurate rotations. For example:
print(math.pi*2) -- 6.28 (full rotation) print(math.pi/2) -- 1.57 (quarter rotation) print(math.pi/4) -- and so on..
We can do the exact same thing when dealing with CFrame.Angles
. For example, if we wanted to set the rotation of a part to 180 degrees on it's Y axis, we could simply say:
part.CFrame = part.CFrame * CFrame.Angles(0,math.pi,0) -- We also need to make sure we're rotating it accordingly to it's current CFrame, so we multiply it by it's current.
And that's about it. If you have any other questions about how this works, I highly suggest checking out this wiki article on CFrame: http://wiki.roblox.com/index.php?title=CFrame#Constructors
Questions
If you're still confused, just let me know and I'll get back to you as soon as possible. Hope it helped.
EDIT
After clearing this up in the chat, I decided to give a better example of how to create a "compiler" for the project you're working on. Here's a CFrame encoder / decoder I whipped up that may be of some use to you: https://www.roblox.com/CFrame-encoder-decoder-module-item?id=402771285
I was in a bit of a rush, so if you have any questions on how it works, let me know.