I can’t figure out how to get TouchPan to work with multiple fingers on the screen. I have these two frames on the screen here and currently it allows you to drag the frame around and the frame follows your finger, but the problem is that I can only use one finger to drag a frame at a time. It doesn’t detect when there are multiple fingers on the screen and it does not allow me to use two fingers (one finger for each frame) to drag both of the frames simultaneously
Here are the two frames:
I believe it might be due to me indexing 1 for the touchPositions, but I’m not sure how to get the indexes for the other fingers if there are multiple fingers on the screen.
local dragging = false
local origin
local frame1 = script.Parent.Frame1
local frame2 = script.Parent.Frame2
local function pan(obj, touchPositions, totalTranslation, velocity, state)
if state == Enum.UserInputState.Begin and not dragging then
dragging = true
origin = touchPositions[1]
elseif state == Enum.UserInputState.Change then
obj.Position = UDim2.fromOffset(origin.X, origin.Y) + UDim2.fromOffset(totalTranslation.X, totalTranslation.Y)
elseif state == Enum.UserInputState.End and dragging then
dragging = false
end
end
frame1.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state)
pan(frame1, touchPositions, totalTranslation, velocity, state)
end)
frame2.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state)
pan(frame2, touchPositions, totalTranslation, velocity, state)
end)