When Rotating Camera 180 degrees with CFrame.Angles it goes up and down

I’m trying to quickly rotate the players camera 180 degrees no matter where they currently have the camera.

When the player is looking up it flips down and in reverse when doing the 180.

I’ve tried messing with the Y and Z but it still ends up doing the same thing. I’ve also tried searching the forum but couldn’t find any similar problems.

Here is the current code

local camera = workspace.CurrentCamera
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(180), 0,0)

3 Likes

Try putting it in a renderStep?

runService:BindToRenderStep("cameraCFrame", Enum.RenderPriority.Camera.Value, function(deltaTime)
    local camera = workspace.CurrentCamera
    camera.CFrame *= CFrame.Angles(0, 0, math.pi)
end)
2 Likes

just change all of the values.

local camera = workspace.CurrentCamera
workspace.CurrentCamera.CFrame = workspace.CurrentCamera.CFrame * CFrame.Angles(math.rad(180), math.rad(180), math.rad(180))
2 Likes

This turns my camera upside down instead of spinning around to the other side of the character. Tried tweaking the other variables but they make the camera go nuts.

Tried this, it ends up not moving the camera at all.

This is happening because you’re rotating the camera 180 degrees relative to its current CFrame. You’re wanting to rotate the camera 180 degrees globally instead of locally. No clue if that makes sense, but what you’d do is apply the current CFrame for the camera after the rotation.

workspace.CurrentCamera.CFrame = CFrame.Angles(0, math.rad(180), 0) * workspace.CurrentCamera.CFrame

Doing this will result in this, which is what I’m assuming you want:

camera-rotation

1 Like

Worked perfectly, Thank you for the detailed explanation. Exactly what I was looking for!