local R={}local x=Ray.new local K=workspace local I=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local t=K.CurrentCamera function R.GetRay(K,R)local I=t:ViewportPointToRay(R.X,R.Y)return x(I.Origin,I.Direction*999)end function R.Cast(U,R,x,I,t)return K:FindPartOnRay(U:GetRay(R),x,I,t)end function R.CastWithIgnoreList(U,R,x,I,t)return K:FindPartOnRayWithIgnoreList(U:GetRay(R),x,I,t)end function R.CastWithWhitelist(t,R,x,I)return K:FindPartOnRayWithWhitelist(t:GetRay(R),x,I)end function R.Start(R) end function R.Init(R)R.TouchStarted=R.Shared.Event.new()R.TouchEnded=R.Shared.Event.new()R.TouchMoved=R.Shared.Event.new()R.TouchTapInWorld=R.Shared.Event.new()R.TouchPinch=R.Shared.Event.new()I.TouchStarted:Connect(function(x,K)if K then return end R.TouchStarted:Fire(x.Position)end)I.TouchEnded:Connect(function(x,K)R.TouchEnded:Fire(x.Position)end)I.TouchMoved:Connect(function(x,K)if K then return end R.TouchMoved:Fire(x.Position,x.Delta)end)I.TouchTapInWorld:Connect(function(x,K)if K then return end R.TouchTapInWorld:Fire(x)end)I.TouchPinch:Connect(function(x,K,I,t,U)if U then return end R.TouchPinch:Fire(K,t)end)end return R
--[[
	
	Mobile.TouchStarted(position)
	Mobile.TouchEnded(position)
	Mobile.TouchMoved(position, delta)
	Mobile.TouchTapInWorld(position)
	Mobile.TouchPinch(scale, state)
	
--]]

local Mobile = {}

local RAY = Ray.new
local workspace = workspace

local userInput = game:GetService("UserInputService")
local cam = workspace.CurrentCamera

function Mobile:GetRay(position)
	local viewportMouseRay = cam:ViewportPointToRay(position.X, position.Y)
	return RAY(viewportMouseRay.Origin, viewportMouseRay.Direction * 999)
end

function Mobile:Cast(position, ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRay(self:GetRay(position), ignoreDescendantsInstance, terrainCellsAreCubes, ignoreWater)
end

function Mobile:CastWithIgnoreList(position, ignoreDescendantsTable, terrainCellsAreCubes, ignoreWater)
	return workspace:FindPartOnRayWithIgnoreList(
		self:GetRay(position),
		ignoreDescendantsTable,
		terrainCellsAreCubes,
		ignoreWater
	)
end

function Mobile:CastWithWhitelist(position, whitelistDescendantsTable, ignoreWater)
	return workspace:FindPartOnRayWithWhitelist(self:GetRay(position), whitelistDescendantsTable, ignoreWater)
end

function Mobile:Start() end

function Mobile:Init()
	self.TouchStarted = self.Shared.Event.new()
	self.TouchEnded = self.Shared.Event.new()
	self.TouchMoved = self.Shared.Event.new()
	self.TouchTapInWorld = self.Shared.Event.new()
	self.TouchPinch = self.Shared.Event.new()

	userInput.TouchStarted:Connect(function(input, processed)
		if processed then
			return
		end
		self.TouchStarted:Fire(input.Position)
	end)

	userInput.TouchEnded:Connect(function(input, processed)
		self.TouchEnded:Fire(input.Position)
	end)

	userInput.TouchMoved:Connect(function(input, processed)
		if processed then
			return
		end
		self.TouchMoved:Fire(input.Position, input.Delta)
	end)

	userInput.TouchTapInWorld:Connect(function(position, processed)
		if processed then
			return
		end
		self.TouchTapInWorld:Fire(position)
	end)

	userInput.TouchPinch:Connect(function(touchPositions, scale, velocity, state, processed)
		if processed then
			return
		end
		self.TouchPinch:Fire(scale, state)
	end)
end

return Mobile
