-- initiate


RunService:BindToRenderStep("Mouse", 5, function(deltaTime)
	if MOUSE.Reticle ~= currentReticle then
		currentReticle	= MOUSE.Reticle
		UpdateReticle()
	end
	
	scopeSpring:Update(deltaTime)
	
	if scope and aiming then
		local ratio	= CAMERA.ViewportSize.Y / CAMERA.ViewportSize.X
		MOUSE_GUI.Position	= UDim2.new(0.5 + scopeSpring.Position.X * 0.02 * ratio, 0, 0.5 + scopeSpring.Position.Y * 0.02, 0)
	else
		MOUSE_GUI.Position	= UDim2.new(0.5, 0, 0.5, 0)
	end
	
	SCOPE_GUI.Position	= MOUSE_GUI.Position
	
	local ignore	= {EFFECTS}
	if PLAYER.Character then
		table.insert(ignore, PLAYER.Character)
	end
	
	local h, pos
	local screenPos	= MOUSE_GUI.AbsolutePosition + MOUSE_GUI.AbsoluteSize / 2
	local ray		= CAMERA:ScreenPointToRay(screenPos.X, screenPos.Y, 0)
	local mouseRay	= Ray.new(CAMERA.CFrame.p, ray.Direction * 1000)
	
	local finished	= false
	
	repeat
		h, pos	= Workspace:FindPartOnRayWithIgnoreList(mouseRay, ignore)
		
		if h then
			if h.Parent:FindFirstChildOfClass("Humanoid") then
				finished	= true
			elseif h.Transparency >= 0.5 then
				table.insert(ignore, h)
			else
				if h.CanCollide then
					finished	= true
				else
					table.insert(ignore, h)
				end
			end
		else
			finished	= true
		end
	until finished
	
	MOUSE.ScreenPosition	= screenPos
	MOUSE.WorldPosition		= pos
end)
