How i can detect a mobile touchmove?

guys, i making a cursor for my game, pc mode working but mobile … doeshn’t(
how i can fix that?

-- Получаем картинку
local image = script.Parent
local uis = game:GetService("UserInputService")
uis.MouseIconEnabled = false
-- Создаем tweening service
local tweenService = game:GetService("TweenService")

-- Функция обновления позиции картинки
local function updateImagePosition(input)
	-- Получаем позицию курсора мыши или касания экрана
	local position
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		position = input.Position
	elseif input.UserInputType == Enum.UserInputType.Touch then
		position = input.Location
	end

	-- Рассчитываем направление движения мыши или касания
	local direction = (position.X - image.Position.X.Offset)

	-- Создаем tweening для картинки
	local tweenInfo = TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
	local tween = tweenService:Create(image, tweenInfo, {Position = UDim2.new(0, position.X, 0, position.Y)})

	-- Добавляем поворот иконки
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		-- Поворот вправо или влево
		if direction > 0 then
			tweenService:Create(image, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 10}):Play()
			wait(0.05)
			tweenService:Create(image, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 0}):Play()
		elseif direction < 0 then
			tweenService:Create(image, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = -10}):Play()
			wait(0.05)
			tweenService:Create(image, TweenInfo.new(0.05, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {Rotation = 0}):Play()
		end
	elseif input.UserInputType == Enum.UserInputType.TouchTap or input.UserInputType == Enum.UserInputType.MouseButton1Down then
		-- Поворот на 360 градусов
		local rotationTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
		local rotationTween = tweenService:Create(image, rotationTweenInfo, {Rotation = 360})
		rotationTween:Play()
	end

	-- Запускаем tweening
	tween:Play()
end

-- Запускаем функцию обновления позиции картинки при движении мыши или касании экрана
uis.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
		updateImagePosition(input)
	end
end)

uis.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch then
		updateImagePosition(input)
	end
end)
2 Likes

Hello If you are going to make a Custom Crosshair, I’m not sure if your game is Set to First-Person Camera Only You can change the Mouse Icon:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Icon = “rbxassetid://YOURIMAGEID”

However, If your game is 3rd Person where you can Zoom In and Zoom Out, and you wanted to achieved First Person Crosshair Only, If Player is not own 1st Person Custom Crosshair would not appear. This works for every device such as PC, Tablet, Mobile whatever you named it :smiley:

–// Variables
local Camera = workspace.Camera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local PlayerGui = Player.PlayerGui
local RunService = game:GetService(“RunService”)
local UserInputService = game:GetService(“UserInputService”)

–// Creates Crosshair
local Crosshair = Instance.new(“ScreenGui”, PlayerGui)
Crosshair.Name = “CustomCrosshair”

local Icon = Instance.new(“ImageLabel”, Crosshair)
Icon.AnchorPoint = Vector2.new(0.5, 0.5)
Icon.BackgroundTransparency = 1
Icon.Size = UDim2.new(0, 53,0, 53)
Icon.Position = UDim2.new(0.5,0,0.5,0)
Icon.Visible = false
Icon.Image = “rbxassetid://15215608197”

while true do
task.wait()

if (Camera.Focus.p-Camera.CoordinateFrame.p).Magnitude <= 1 then
Icon.Visible = true
UserInputService.MouseIconEnabled = false
else
if (Camera.Focus.p-Camera.CoordinateFrame.p).Magnitude > 1 then
Icon.Visible = false
UserInputService.MouseIconEnabled = true
end

end

end

thanks, but i know it already(
i mean on mobile my crosshair don’t follow last mobile touch’s - how i can fix that? or it impossible

1 Like

Can you provide an exact detail? I’m quite confused