How to make a Camera Z Axis Popper?

I just made a post asking for help with my camera system, but I need some more help! When you use ROBLOX’s Shift Lock Camera Mode where it will zoom and unzoom your camera based on what’s intersecting with the camera to prevent any clipping; how would I go about this? I have been trying for weeks and I can’t seem to figure it out. I’ve read the popper cam code, but I can’t figure it out.

1 Like

Try raycasting every render step frame from character head’s position to camera’s cframe position and if the ray hits something (like some part) you get the position where it hit that part and set camera’s cframe to that position. But dont forget to preserve camera’s rotation (you can get it before setting camera’s cframe to a new position, and then after setting camera’s cframe to that position - where a ray hit some part - just multiply it by rotation so that the rotation is preserved).

This might help
https://developer.roblox.com/en-us/api-reference/function/Camera/WorldToScreenPoint

How do I get the camera’s rotation from a CFrame?

GetPartsObscuringTarget should help out too.

1 Like
local camera = workspace.CurrentCamera

-- <maybe some code in here>

-- this will return camera's current rotation IN RADIANS
local rotationX, rotationY, rotationZ = camera.CFrame:ToEulerAnglesXYZ()