local T={}local q=Ray.new local H=workspace local r=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local n=H.CurrentCamera function T.GetRay(H,T)local r=n:ViewportPointToRay(T.X,T.Y)return q(r.Origin,r.Direction*999)end function T.Cast(s,T,q,r,n)return H:FindPartOnRay(s:GetRay(T),q,r,n)end function T.CastWithIgnoreList(s,T,q,r,n)return H:FindPartOnRayWithIgnoreList(s:GetRay(T),q,r,n)end function T.CastWithWhitelist(n,T,q,r)return H:FindPartOnRayWithWhitelist(n:GetRay(T),q,r)end function T.Start(T) end function T.Init(T)T.TouchStarted=T.Shared.Event.new()T.TouchEnded=T.Shared.Event.new()T.TouchMoved=T.Shared.Event.new()T.TouchTapInWorld=T.Shared.Event.new()T.TouchPinch=T.Shared.Event.new()r.TouchStarted:Connect(function(q,H)if H then return end T.TouchStarted:Fire(q.Position)end)r.TouchEnded:Connect(function(q,H)T.TouchEnded:Fire(q.Position)end)r.TouchMoved:Connect(function(q,H)if H then return end T.TouchMoved:Fire(q.Position,q.Delta)end)r.TouchTapInWorld:Connect(function(q,H)if H then return end T.TouchTapInWorld:Fire(q)end)r.TouchPinch:Connect(function(q,H,r,n,s)if s then return end T.TouchPinch:Fire(H,n)end)end return T
-- Mobile
-- Crazyman32
-- December 28, 2017

--[[
	
	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
