How to make GUI object follow touch

I am trying to make a custom second joystick for mobile. I want to make my image button follow the players touch when they press and drag it. I don’t know where to start with this. Thanks

imageButton.InputBegan:Connect(function(inputObj: InputObject, gp)
     if inputObj.UserInputType == Enum.UserInputType.Touch then
	     --make imageButton follow touch
     end
end)
1 Like

You can do the following:

imageButton.InputChanged:Connect(function(inputObj : InputObject, gp : boolean)
	if gp then
		return
	end
	
	if inputObj.UserInputType == Enum.UserInputType.Touch then
		local touchPosition = inputObj.Position
		imageButton.Position = UDim2.new(0, touchPosition.X-36, 0, touchPosition.Y-36)
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.