Getting pitch and yaw of the CurrentCamera

How would I get the pitch and yaw of the camera? The wiki doesn’t state anything about the pitch and yaw, only the roll.

local Camera = workspace.CurrentCamera

local function GetCameraPitchYawRoll(Camera : Camera): (number, number, number)
	return Camera.CFrame:ToOrientation() --given in degrees
end

local degPitch, degYaw, degRoll = GetCameraPitchYawRoll(Camera)
2 Likes

Oh thank you, one more thing, is it possible to specify what you want from the function? Like, yaw = “”

You can use _ to omit variables that a function returns, for example if I just wanted the yaw of the camera:

local _, Yaw = GetCameraPitchYawRoll(Camera)
1 Like

Great! If I had to change the pitch, would I have to rearrange the variables like Pitch, _ or

If you want to actually change the pitch of the camera, you’d have to use a separate function

local function AdjustPitch(Camera : Camera, Degrees: number)
	Camera.CFrame *= CFrame.Angles(math.rad(Degrees),0,0)
end

However if you want to get the pitch from the original GetCameraPitchYawRoll function, you have the right idea, but the last _ isn’t necessary since you’re just getting the first argument that the function returns.

1 Like

Oh I badly worded it, but this might be helpful in the future, thanks.

1 Like

note: CFrame:ToOrientation() returns radians not degrees

edit: maybe there’s something wrong with my code, bcuz the wiki says ToOrientation is equivalent to toEulerAnglesYXZ, but I’m getting something different compared to toEulerAnglesYXZ