function CameraModule.new(f,S,m,x)local s={}s.Position=f s.Rotation=S s.CFrame=CFrame.new(f)*CFrame.Angles(math.rad(S.X),math.rad(S.Y),math.rad(S.Z))s.Target=Vector3.new(1,0,0)s.PressedKey=nil s.fpsController={direction=0,pitch=0}s.Sensitivity=m Mouse.KeyDown:Connect(function(f)s.PressedKey=f end)Mouse.KeyUp:Connect(function()s.PressedKey=nil end)function s.Movement(f)local S=s.PressedKey if S=="\101"then s.CFrame+=Vector3.new(0,.4,0)elseif S=="\113"then s.CFrame-=Vector3.new(0,.4,0)elseif S=="\119"then s.CFrame+=Vector3.new(.4*math.cos(-s.Rotation.Y),0,.4*math.sin(-s.Rotation.Y))elseif S=="\115"then s.CFrame-=Vector3.new(.4*math.cos(-s.Rotation.Y),0,.4*math.sin(-s.Rotation.Y))elseif S=="\097"then s.CFrame+=Vector3.new(.4*math.sin(-s.Rotation.Y),0,-0.4*math.cos(-s.Rotation.Y))elseif S=="\100"then s.CFrame+=Vector3.new(-0.4*math.sin(-s.Rotation.Y),0,.4*math.cos(-s.Rotation.Y))end task.synchronize()s:Pan((UserInput:GetMouseDelta()).X,(UserInput:GetMouseDelta()).Y)task.desynchronize()end function s.Pan(m,f,S)s.fpsController.direction=math.max(math.min(s.fpsController.direction-S*s.Sensitivity,math.pi*.5),math.pi*-0.5)s.fpsController.pitch=s.fpsController.pitch-f*s.Sensitivity local x=CFrame.Angles(0,s.fpsController.pitch,0)*CFrame.Angles(s.fpsController.direction,0,0)local H=CFrame.new(s.CFrame.Position)s.CFrame=H*x end function s.Update(f)s.Position=s.CFrame.Position local S,m,H=s.CFrame:ToOrientation()s.Rotation=Vector3.new(S,m+math.rad(90),0)if x==true then s:Movement()end end return s end return CameraModule
--UserInput.MouseBehavior = Enum.MouseBehavior.LockCenter

function CameraModule.new(Position, Rotation, Sensitivity, move)
	local Camera = {}

	Camera.Position = Position
	Camera.Rotation = Rotation
	Camera.CFrame = CFrame.new(Position)
		* CFrame.Angles(math.rad(Rotation.X), math.rad(Rotation.Y), math.rad(Rotation.Z))
	Camera.Target = Vector3.new(1, 0, 0)
	Camera.PressedKey = nil

	Camera.fpsController = {
		direction = 0,
		pitch = 0,
	}

	Camera.Sensitivity = Sensitivity

	Mouse.KeyDown:Connect(function(key)
		Camera.PressedKey = key
	end)

	Mouse.KeyUp:Connect(function()
		Camera.PressedKey = nil
	end)

	function Camera:Movement()
		local key = Camera.PressedKey

		if key == "e" then
			Camera.CFrame += Vector3.new(0, 0.4, 0)
		elseif key == "q" then
			Camera.CFrame -= Vector3.new(0, 0.4, 0)
		elseif key == "w" then
			Camera.CFrame += Vector3.new(0.4 * math.cos(-Camera.Rotation.Y), 0, 0.4 * math.sin(-Camera.Rotation.Y))
		elseif key == "s" then
			Camera.CFrame -= Vector3.new(0.4 * math.cos(-Camera.Rotation.Y), 0, 0.4 * math.sin(-Camera.Rotation.Y))
		elseif key == "a" then
			Camera.CFrame += Vector3.new(0.4 * math.sin(-Camera.Rotation.Y), 0, -0.4 * math.cos(-Camera.Rotation.Y))
		elseif key == "d" then
			Camera.CFrame += Vector3.new(-0.4 * math.sin(-Camera.Rotation.Y), 0, 0.4 * math.cos(-Camera.Rotation.Y))
		end

		task.synchronize()
		Camera:Pan(UserInput:GetMouseDelta().X, UserInput:GetMouseDelta().Y)
		task.desynchronize()
	end

	function Camera:Pan(dx, dy)
		Camera.fpsController.direction =
			math.max(math.min(Camera.fpsController.direction - dy * Camera.Sensitivity, math.pi * 0.5), math.pi * -0.5)
		Camera.fpsController.pitch = Camera.fpsController.pitch - dx * Camera.Sensitivity

		local rotationCFrame = CFrame.Angles(0, Camera.fpsController.pitch, 0)
			* CFrame.Angles(Camera.fpsController.direction, 0, 0)
		local positionCFrame = CFrame.new(Camera.CFrame.Position)

		Camera.CFrame = positionCFrame * rotationCFrame
	end

	function Camera:Update()
		Camera.Position = Camera.CFrame.Position
		local xRotation, yRotation, _ = Camera.CFrame:ToOrientation()
		Camera.Rotation = Vector3.new(xRotation, yRotation + math.rad(90), 0)

		if move == true then
			Camera:Movement()
		end
	end

	return Camera
end

return CameraModule
