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?
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
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
z fields mean that the
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 = CFrame.new(humanoidRootPart.Position) local result = position * rotation character:SetPrimaryPartCFrame(result)