Camera That Follows Mouse Is Buggy?

This is a script where it makes the camera follow the mouse, similar to FNaF’s camera

I’m going to make myself clear, I didn’t make this script.
I just got it off this forum, and messed with it to get the result I wanted

The issue here is that it’s not covering the whole space

local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local camPart = workspace.CamPart

local rotateAmount = 30
local fov = 70 

local function enable()    
	camera.CameraType = Enum.CameraType.Scriptable
	camera.FieldOfView = fov
	camera.CFrame = camPart.CFrame
	game:GetService("RunService"):BindToRenderStep("CameraLookAtMouse", Enum.RenderPriority.Camera.Value + 1, function()
		camera.CFrame = camPart.CFrame * CFrame.Angles(
			0,
			math.rad((mouse.X - mouse.ViewSizeX) / mouse.ViewSizeX * -rotateAmount),
			0
		)
	end)
end

local function disable()
	game:GetService("RunService"):UnbindFromRenderStep("CameraLookAtMouse")
	camera.CameraType = Enum.CameraType.Custom
end

enable()

Video: robloxapp-20230211-1838354.wmv (528.8 KB)

Original Script (it’s the solution): How would I make a fnaf style camera? - #7 by Noti_fied

1 Like

The calculation for the Y axis is somewhat incorrect. Try this:

math.rad((mouse.X - (mouse.ViewSizeX / 2)) / mouse.ViewSizeX * -rotateAmount) * 2

this broke the script somehow :confused:

How did it break? Please elaborate, and send the updated version of your code.


local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local camPart = workspace.CamPart

local rotateAmount = 30
local fov = 70 

local function enable()    
	camera.CameraType = Enum.CameraType.Scriptable
	camera.FieldOfView = fov
	camera.CFrame = camPart.CFrame
	game:GetService("RunService"):BindToRenderStep("CameraLookAtMouse", Enum.RenderPriority.Camera.Value + 1, function()
		camera.CFrame = camPart.CFrame * CFrame.Angles(
			0,
			math.rad((mouse.X - (mouse.ViewSizeX / 2)) / mouse.ViewSizeX * -rotateAmount) * 2,
			0
		)
	end)
end

local function disable()
	game:GetService("RunService"):UnbindFromRenderStep("CameraLookAtMouse")
	camera.CameraType = Enum.CameraType.Custom
end

enable()

Can you at least describe or provide an output? I was only asking for the code just to make sure you have set the fix correctly, now I want to know how did the code break. Please give more effort to responding instead of “it won’t work” replies.

18:56:27.755 Workspace.H2nad.LocalScript:17: Expected ‘)’ (to close ‘(’ at line 14), got ‘0’ - Studio - LocalScript:17

also, you did not ask for the output?

I fixed it, thank you very much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.