# CFrame axis rotation help

https://gyazo.com/2fb3a3724f81b5dce165a0389a2512bd.mp4
I have a brick rotating like this, in an Orientation `0, n, 0`.

``````for i = 1, 100 do
local a = workspace.Part

local RX, RY, RZ = workspace.Part.CFrame:toOrientation();
local NewCFrame = CFrame.new(workspace.Part.CFrame.p) * CFrame.fromOrientation(0, RY, 0);
a.CFrame = NewCFrame * CFrame.Angles(0, .1, 0);
end
``````

How do I make a brick rotate like this? With Orientation `0, n, 90`.
https://gyazo.com/bdfe97de0e15590f79ec6f3033c7afab.mp4

It should use :toOrientation() and :fromOrientation().

1 Like

If youâ€™re looking to rotate your brick like that, you will need to put in a `math.rad(90)` at the z in your `* CFrames.Angles(0, .1, 0)` part of your code.

``````for i = 1, 100 do
local a = workspace.Part

local RX, RY, RZ = a.CFrame:toOrientation();
local NewCFrame = CFrame.new(workspace.Part.CFrame.p) * CFrame.fromOrientation(0, RY, 0);
a.CFrame = NewCFrame * CFrame.Angles(0, .1, math.rad(90));
end
``````
3 Likes

Axis aside, as written, this code probably isnâ€™t doing what you intended. There is no form of wait() in this loop, so itâ€™s changing the CFrame of the part 100 times for every 1 time it gets rendered (assuming there is some outer loop). So this whole loop above is just a very expensive way to do one 10-radians rotation. 10 radians is 2 full rotations plus about 1.6 degrees, whereas 0.1 radians is more like 5.7 degrees.

Additionally, if you mean for the part to rotate in place, you should just multiply its CFrame by the rotation CFrame. Youâ€™re additionally making the part orbit the origin, by some amount that corresponds to itâ€™s previous local orientation. This is a rather complex behavior and itâ€™s not clear to me if itâ€™s intentional, or if you just havenâ€™t noticed it yet because your part happens to be at 0,0,0.

1 Like