Changing camera to go in infinity motion?

This is what I’m trying to achieve with the camera as camera bob. This is the link that my math teacher suggested:

I used the parametric equations to keep track of the x and y values to use as it updates the camera cframe but it doesn’t not do what it’s supposed to do, swaying the camera side to side and does not allow the camera to look down (when I drag mouse down it does not allow me to and shift it back to the middle)

Here is the code that I have for this specific segment:

UIS.InputBegan:Connect(function(key)
	print(key.KeyCode == Enum.KeyCode.W)
	if key.KeyCode == Enum.KeyCode.W and isEquipped and not isWDown then
		isWDown = true
		local XandY = 0
		local moveCframe
		moveCframe = runService.RenderStepped:Connect(function()
			task.wait()
			camera.CFrame = CFrame.new(0.5 * (math.cos(XandY)), 2 * (math.sin(XandY) * math.cos(XandY)), camera.CFrame.Z) * camera.CFrame.Rotation
			--camera.CFrame.Rotation
			XandY += math.pi / 24
			if not isWDown then
				moveCframe:Disconnect()
			end
		end)
	end
end)

I have just updated the code a little bit. This reply was just to revive this topic as I still need help :frowning: