I’ve written different swipe detection scripts and tried some from the web (for example: portfolio) but i’ve had the same problem with all of them.
The swipe detections works great but if you alternately and repeatedly tap the left and right side of the screen it registers as a swipe.
If you force the swipe time to be longer than about 0.1 the problem disappear but then you can’t detect short and fast swipes.
Has anyone encountered this problem or have a solution?
Well, the script you’ve linked is simply not designed for multitouch at all. As soon as you have more than one touch at the same time you have to track the fingerID of a touch or you’ll end up in a total mess.
I’ve written a swipe and tap detection script a while ago. Note: This will only detect a swipe of the first finger that touches the screen. It can easily be changed to only detect the last finger by removing the && SwipeID == -1
in line 24. If you want to be able to detect a swipe with any finger it get’s way more complicated since you have to save the state for each finger. The state includes the fingerID and startpos. If you also want to implement a max swipe time you need the starttime as well. However limiting the time and distance of a swipe might frustrates some players if you got the timing wrong.
For example Subway surfers don’t limit the time at all. You can keep your finger on the screen as long as you want. As soon as you move it more than the min distance they will trigger a swipe.
My script does the same. It doesn’t wait for the TouchEnded state so the user doesn’t need to lift the finger to make the game register the swipe. It results in a more responsive control.