Still have questions? Join our Discord server and get real time help.
Log in to vote

How to get ONE rotation value from a CFrame?

Asked by 2 years ago

After having learned how to put one position with another rotation, I now need to figure out how to get one rotation value (rY). I'm trying to rotate my character depending on the direction of the camera, except I only want the character to be able to spin along the y axis, not the x or z, or else he won't be standing up straight. So, how would I simply get the rotation value of the camera on the Y axis while leaving the Z and X at 0?

1 answer

Log in to vote
Answered by
RayCurse 1508 Moderation Voter
2 years ago
Edited 2 years ago

The rotational part of CFrames can be converted to Euler angles. This is basically three numbers representing the rotation of each of the three axes. We can get the Euler angles of a CFrame called cf by doing local x , y , z = cf:ToEulerAngles(). We can then construct a rotational CFrame again using CFrame.Angles(0 , y , 0). The zeroes in the x and z fields mean that the x and z angles of the character won't be changed.

local camera = workspace.CurrentCamera
local x , y , z = camera.CFrame:ToEulerAngles()

local rotation = CFrame.Angles(0 , y , 0)
local position =

local result = position * rotation

Thanks again! I've learned so much from you today lol cowsoncows 779 — 2y
For the record. As of 2019 the method is now `:ToEulerAnglesXYZ()` joeldes 201 — 1y

Answer this question