Modify CameraModule to limit angles

Hello fellow developers! So I am working on my Rake game (I’m not gonna explain in details) and I want to edit CameraModule to make it work like in this game, is it possible without creating custom camera system?

1 Like

I (for personal reasons) cannot play games right now.

However, if you do decide to change your mind and go in detail about what you mean, I may be able to help.

The Camera system in game I linked works like when you look in sides it doesn’t move (rotate) your character until some angle is reached (sorry if It’s bad explanation I’m bad explainer)

You’re going to want to change the current camera’s CFrame every RenderStep. You will need the orientation of the CFrame so that you can limit the angle and then reconstruct the CFrame. The sample I have is crude and has stuttering issues if you look down too fast though. It’s also independent of modifying the CameraModule. You can use it as a guideline for what to expect when approaching this.

local RunService = game:GetService("RunService")

local LIMIT_ANGLE = 45

RunService:BindToRenderStep("LimitCameraAngleX", Enum.RenderPriority.Camera.Value + 1, function()
	local currentCamera = workspace.CurrentCamera
	local cameraCFrame = currentCamera.CFrame
	
	-- Break the camera's orientation into its XYZ components in radians
	local rotX, rotY, rotZ = cameraCFrame:ToOrientation()
	
	-- Convert radians to degrees, clamp according to LIMIT_ANGLE then convert back to radians
	rotX = math.rad(math.clamp(math.deg(rotX), -LIMIT_ANGLE, LIMIT_ANGLE))
	
	-- Reconstruct camera CFrame with original position and new orientations
	currentCamera.CFrame = CFrame.new(cameraCFrame.Position) * CFrame.fromOrientation(rotX, rotY, rotZ)
end)
2 Likes

When I try to limit Y rotation it makes camera twitch.

how can you make this but it only limits it looking down