Help With Camera

This script pretty much make the camera follow the mouse like in this video

Problem: Player spawn camera is titled by 10

This is because the maxTilt = 10 and the updateCamera function updates the camera, making the camera be titled when player joins.

How do I make the camera have no tilt when the player joins?

Code:

--=========================================================================================================
--STARTERPLAYERSCRIPTS >> CORE >> LOCAL SCRIPT
--=========================================================================================================
--<<VARIABLES>>
local cam = workspace.CurrentCamera
local camPart = workspace.MainMenu:WaitForChild("CameraPart")
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
local mainMenu = script.Parent.MainMenu
local maxTilt = 10
--=========================================================================================================
--<<FUNCTIONS>>
-- Function to handle camera tilt based on mouse movement
local function updateCamera()
	cam.CFrame = camPart.CFrame * CFrame.Angles(
		math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -maxTilt),
		math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -maxTilt),
		0
	)
end

-- Function to stop camera movement and reset to player's view
local function resetCamera()
	cam.CameraType = Enum.CameraType.Custom
end

-- Connects a RenderStepped function to update the camera's CFrame based on mouse movement
game:GetService("RunService").RenderStepped:Connect(function()
	if mainMenu.Value == "Play" then
		resetCamera()
	else
		updateCamera()
	end
end)
--=========================================================================================================
--<<NOTES>>
-- This LocalScript adjusts the orientation of the camera based on mouse movement
-- It sets the CameraType to Scriptable and continuously updates the camera's CFrame to simulate tilting
-- The maxTilt variable defines the maximum tilt angle for the camera
-- If mainMenu's value is "Play," it stops camera movement and resets to the player's view
--=========================================================================================================
3 Likes

I am up with this as an idea

local function startCamera()
	cam.CFrame = camPart.CFrame * CFrame.Angles(0, 0, 0)
end

but when I run the function the updateCamera function does not work.

1 Like

Cool! I hope someone helps you. I certainly can’t.

Can’t you utilize math.clamp() for this?

local R = math.rad(200) -- Replace with the radian equation you use in your CFrame.Angles maniupl
local X = 0
task.spawn(function()
	for i = 1, 10 do
		task.wait(1) -- Can be any number
		X += 1
	end
end)

print(math.clamp(R, -X, X))
1 Like