How would I make a camera follow the player's mouse? (Enter the Gungeon)

Why is noone using MS.X or MS.Y? I rewrote the script you gave to use the mouse 2D position instead of the mouse 3D position.

local RunService = game:GetService('RunService')

local Plr = game:GetService('Players').LocalPlayer
local MS = Plr:GetMouse()

local Camera = workspace.CurrentCamera

local CAMERA_DEPTH = 24
local HEIGHT_OFFSET = 1.5 -- 1.5 is the distance from the root part to the head

local function updateCamera()
	local Char = Plr.Character
	
	if Char then
		local rootPart:BasePart = Char:FindFirstChild("HumanoidRootPart")
		
		if rootPart then
			local Center = Camera.ViewportSize / 2
			local Offset = (Vector2.new(MS.X,MS.Y) - Center) / Camera.ViewportSize
			Offset *= 5 -- max 5 studs in all directions
			
			local Pos = (Vector3.new(0, HEIGHT_OFFSET, 0) + rootPart.Position) + Vector3.new(Offset.X,-Offset.Y,0)
			
			Camera.CFrame = CFrame.new(Pos.X, Pos.Y, rootPos.Z + CAMERA_DEPTH)
		end
	end
end

RunService:BindToRenderStep("SidescrollingCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)
1 Like