Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Input.Touches - Simple Gesture Solution

Discussion in 'Assets and Asset Store' started by Song_Tan, Apr 28, 2012.

  1. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your interest. Fyi, it does support multi-instance of drag by multiple fingers. The demo actually works that way when build on a multi-touch device. However the problem is it only works for device which touch input system is support by Unity. I cant vouch for your case since I'm not sure if Unity supports the system you are going to use.
     
  2. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    Hey Songtan,

    So I have recently published my game to the app store, with Input Touches.
    I only now notice that I am getting error reports sent to my log and it looks like they are coming from the plugin.

    I never saw this error when running in the editor, or when running on my device, so I have no idea how to reproduce it yet.

    If you have any clue, let me know.

    This is the error report I get:
    IndexOutOfRangeException: Array index is out of range.
    TapDetector.CheckMultiTapTouch (Int32 index, Vector2 pos) TapDetector+c__Iterator9.MoveNext ()
     
    Last edited: Mar 26, 2013
  3. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    Can we have the ability to turn the gesture detection on and off?

    Code (csharp):
    1. Gesture.enabled = false;
    It would also need to make sure that on setting to true previous gestures are cleared out.

    I know it's easy to make the change to the detectors but I like to keep my plugins pure so they are easy to update mid project.

    If that's not possible, how about making your classes inheritable (make all functions protected/public virtual and all private variables protected) so we can add features without breaking your code?
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Sorry for the slow respond guys, I've been away for the past few days.

    @Danny, I suspect the cause of the error is that you are having two many finger on screen at once. There's a cap of 5 fingers max from my code. I suppose this is my fault of course. Shouldnt have hard-code this. Anyway try this to fix the error. Change line 35 and 36 in TapDetector.cs to following:

    Code (csharp):
    1.     private MultiTapTracker[] multiTapMFTouch=new MultiTapTracker[20];
    2.     private MultiTapTracker[] multiTapTouch=new MultiTapTracker[20];
    It's a quick fix of course. And it will increase the maximum finger count to 20.


    @Trooper, I'll keep that in mind and see what I can do. But honestly I'm quite busy recently so dont expect an update/change anytime soon.
     
  5. DannyB

    DannyB

    Joined:
    Jun 20, 2012
    Posts:
    214
    @Songtan - thanks a lot!

    Will try that. A cap of 5 fingers is probably good, as long as it does not generate exceptions.
    Will you do something about it in one of the next releases?

    I will try to reproduce the error so I can be sure that this was it indeed - I am not sleeping well when I know there are errors in production builds... :)

    EDIT: Songtan - you are awesome! I just touched with 7 fingers on my iPad, and immediately got a report of the error. You are a life saver.
     
    Last edited: Mar 27, 2013
  6. gregmax17

    gregmax17

    Joined:
    Jan 23, 2011
    Posts:
    186
    Hello, I am wondering if there is a way to detect and limit the swipe end points...? Let me try to explain. I am currently using the swipe detection to determine the speed of the swipe (in the editor). But I don't think the 'speed' of the swipe will be the same from the editor compared to the iOS device I use because in the editor I can drag/continue my swipe outside of the game window.

    Is it possible to have an option to detect if the swipe is outside of the screen's width/height it ends the swipe? Hopefully I am making sense.
     
  7. subone

    subone

    Joined:
    Feb 27, 2013
    Posts:
    26
    @SongTan,
    I am trying to use this asset to make a game similar to the one in this video :



    And I am confused :confused: . I am trying to use flick, but the sphere is moving only right, left , up , and down. And I want to move it forward.
    What should I do?
     
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I take it by flick you mean swipe event? Or are you using FlickDemo?

    Fyi the FlickDemo is meant for 2D only. You cant just use it and expect the ball to start to work like how it's in the video you show me. I'm afraid you will have to understand how to use the information passed by the swipe event to interact with the ball. Basically what you need is to listen to swipeEnd event, use the swipe direction to kick the ball and perhaps the speed or magnitude to modify the ball speed/height or what not. There are multiple ways as to how to "kick" the ball. You will have to figure out what are the method you want to use.
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Please note that I'll be away for a few days. If you have any issue, please leave a message here or send me an email. I'll get back to you as soon as possible. Sorry for any inconvenience.


    Edit: I'm now back so normal service has been resumed!
     
    Last edited: May 7, 2013
  10. Ken-T

    Ken-T

    Joined:
    Jun 15, 2012
    Posts:
    19
    Hi

    I am using the Pinch and Rotate gestures in iOS to adjust a camera.
    It was working perfectly until I added a UIView overlay to improve the
    look of the controls. Dragging still works but the Pinch and Rotate are not
    called. Any idea why? Mutli-touch is turned on in the over laying view.

    Thanks,

    Ken
     
  11. Ken-T

    Ken-T

    Joined:
    Jun 15, 2012
    Posts:
    19
    This fixed it:

    Code (csharp):
    1. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    2.     [self.superview touchesBegan:touches withEvent:event];
    3. }
    4. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    5.     [self.superview touchesMoved:touches withEvent:event];
    6. }
    7. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    8.     [self.superview touchesEnded:touches withEvent:event];
    9. }
    10. - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    11.     [self.superview touchesCancelled:touches withEvent:event];
    12. }
    Not sure why the drags worked before.
     
  12. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Hi Ken,

    I've never try to modify anything in XCode beyond the unity default build so I wasnt aware of that. Thanks for letting me know.

    And sorry for being away and not being all that helpful.
     
    Last edited: May 7, 2013
  13. seanbro

    seanbro

    Joined:
    Apr 25, 2013
    Posts:
    13
    I just bought this script and I can't figure out how to fire OnSwipeEndE only once. My OnSwipeEnd function fires several times on a long, single swipe. I only want the finished swipe, when the finger is lifted.

    Code (csharp):
    1.  
    2. function OnEnable(){
    3.     Gesture.onSwipeEndE += OnSwipeEnd;
    4. }
    5. function OnSwipeEnd(sw:SwipeInfo){
    6.     //this prints continuously without lifting the input
    7.     print("swiped");
    8. }
    9.  
     
  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for your purchase. :)

    If you look at the Gesture prefab, there's a swipe detector component which allow you to set some parameter about the swipe. This include the maximum swipe duration allowed. By default this is set to 0.5 for a relatively quick fast. You can increase this value to allow longer swipe duration. You might also want to decrease the minimum swipe speed if you arent looking for a fast swipe.
     
  15. seanbro

    seanbro

    Joined:
    Apr 25, 2013
    Posts:
    13
    I only want to allow quick swipes, and I need to detect them as separate touches. If someone exceeds the maximum swipe duration or maximum direction change without lifting their finger, shouldn't the swipe be cancelled rather than ended? Is there any way to ensure that every swipe has its own TouchPhase.Began and TouchPhase.Ended ?

    Also, is there any way to differentiate between a tap and the TouchPhase.Began of a swipe? If I am trying to capture both gestures, but onMultiTapE fires every time I touch the screen, even if it is the beginning of a swipe and my finger is still pressing the screen.

    My ultimate goal is to capture a series of 3 quick, separate touches, which could be Tap-Tap-Swipe, Tap-Swipe-Tap, Swipe-Swipe-Swipe, etc. Any advice how I could do that without false positives?
     
    Last edited: May 9, 2013
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Swipe event wont be cancel. They will be terminate and register as one as soon as it breaks any of the required criteria. But you can check the speed/duration/distance of each swipe to determine if the event should be used. Fyi, there are 2 events for when swipe begin or end, namely onSwipeStartE and onSwipeEndE. Please note that onSwipeEndE doesnt subject to some of the specific swipe criteria so you will have to check the condition.

    For your application, I dont see any problem if you just use onMultiTapE and onSwipeE. A tap wouldnt be registered as swipe or swipe start event. as you need to move your finger across the screen for a minimum amount before it registered itself as a swipe where for validation tap, the tolerance of the finger movement is very low. You might want to set the maxMultiTapCount in TapDetector to 1.

    Not sure if that explain thing sufficiently. Do let me know if you need anything more specific.
     
  17. SkaredCreations

    SkaredCreations

    Joined:
    Sep 29, 2010
    Posts:
    296
    Great tool, I use this plugins in every project. By the way I found a bug in BasicDetector where it wrongly associates GetMouseButtonDown(2) instead of GetMouseButtonDown(1) to right mouse events (Gesture.OnMouse2*).
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You are right! Thanks for letting me know. :)
     
  19. tty_Yamada

    tty_Yamada

    Joined:
    Jun 10, 2013
    Posts:
    2
    Hi.
    Our project is using Input.Touches.
    This Asset is great for us,
    But we have a problem.

    Input.Touches was bought me.
    How many Assets should we buy?

    Our projects using TeamAssetServer.
    So Input.Touches is used by five.
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Hi Yamada, thanks for using the InputTouches.

    According to the default asset store license, the term of usage is the same as the license for unity editor. So that's 1 copy for each user. That's strictly legal speaking of course.

    However in paractice, you dont really need all 5 copy for it to work on AssetServer. So it's up to you really. I dont really mind and as a humble single developer, I dont have the means to enforce it. If your team can afford it, I would appreaciate your honor the term of license. If not, it's ok. I'm still happy to provide you the support you need.
     
  21. tty_Yamada

    tty_Yamada

    Joined:
    Jun 10, 2013
    Posts:
    2
    Thank you for your kindness!
    We will buy Input.Touches by each member before Release.
     
  22. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    Hi Song Tan, i just bought you script, and its really nice! how can i implement a two fingers drag?

    im tryin this:
    function OnDragging(dragInfo:DragInfo)
    {
    if(dragInfo.fingerCount==2){
    pan=0;
    message.message="two finger";
    }
    if(dragInfo.fingerCount==1){
    pan=1;
    message.message="one finger";
    }
    }


    (WEll in fact what i need is a two finger orbitcam, )
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    There's an example of of multi-finger drag in the example RTSCam. You are pretty much on the right track there. The only thing you need to change is to listen to onMFDraggingE instead of onDraggingE. onMFDraggingE is for dragging event with 2 or more fingers wheres onDraggingE is drag event for one finger only.
     
  24. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    hi SongTan, thank you for your quick answer on my last question,

    I use your RTSCam javascript as templete to my script, and it works almost perfect,
    but i noticed something:
    The two finger drag only work when you put first one finger then the second. I think two finger drag didnt work if you insert both fingers in the same frame... its ok if the software was 50 fps, but my app have many polygons and sometimes it went to 10-12 fps...
    can you take a look in it?
     
  25. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Thanks for letting me know. I've checked and it's in fact a bug. I'll fix it and send an advance update to you.
     
  26. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    Wow, tis fixed, thank you for the quick solution!
     
  27. _Max_

    _Max_

    Joined:
    Feb 21, 2013
    Posts:
    160
    Hi, I'm waiting for update before asset store purchase -> seems last update was last year or so?
    Can we have small update
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I've in fact just submitted an update which fixed all the issues raised since the last update. It will take some time (a few days on average) for AssetStore admin to approve it.

    I'll post an update here when the update is on AssetStore.
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Just a quick note that a new update (v1.1.3f1) is now live on AssetStore.
     
  30. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38
    Hey there I just sent you an email support for combinning different gestures on single object, which we're haing a hard time to achieve, thx!
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    And I have responded to your email. :)
     
  32. JustDave1961

    JustDave1961

    Joined:
    Jan 5, 2013
    Posts:
    14
    Unfortunately, this input asset implements taps wrong just like all the others in the asset store.

    I bought this for the tap and touch down functionality. It doesn't work the way it should, the Tap function is wrong.

    A Tap is NOT time based as implemented! A time based 'tap' is actually a press action.

    A Tap is when the user touches and releases on the same object/sprite/whatever.
    The user can do this quickly, hold their finger on the object all day or move their finger off then back onto the object as long as the down and up press are on the same object, it's a tap. That's it.

    I ended up implementing it myself. Very frustrating.
     
  33. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38
    +1 with JustDave1961 i agree tap action is wrong, well yes songtan you responded but we have no solution...your code is very responsive but needs to work with each other gesture. We tested your prefab 5 minutes on a simple plane which had tap, double tap, swipe and swipe rotate and everything was being executed at the same time (swipe rotate would swipe in translation, double tap would double tap plus a tap, etc...). I think your code and documentation are pretty clear, support within an hour was very appreciated but you gave us no clue to sort this very common gesture recognition issue. I would be fair for future buyers to let them know they can't mix different prefabs on the same object from scratch without direct issue. We've been trying to fix this since this morning, including boolean in your code to say don't rotate if you swipe or don't translate if you swipe rotate...
    Anyway, i hope we can come up with a solution soon, if you have any clue songtan i'd really appreciate.
    As JustDave1961 said we also started up implementing your code after 15 minutes testing. A bit of a pain.
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm sorry to have cause the confusion and disappointment. I'll try my best to sort out the issue. However I must say that I dont agree with the Tap is wrongly implemented. First there's no absolute definition of Tap that say they are not time based like it's claimed by JustDave1961. It's a loose term at best. Given the phase double-tap, it's more logical to interpret it as time based.

    I dont really want to argue on this. But there's a variable 'short tap time' on TapDetector component (on Gesture prefab) which is the maximum tap time allowed. You can set the to a relatively large value (say 100second or even much longer) and that time would become irrelevant factor to the tap event. There are other variable as well which allow you to modify the behaviour of each gesture detect/ignored. And you can disable certain component on the 'Gesture' prefab to disable certain type of gesture entirely.

    @Spartan_Boy, I'm not sure what exactly you are trying to do so I cant really give you a specific solution earlier. And I wasn't sure if you are completely stuck or havent gone through the example to see if there's a possible solution. So I can only give you a general answer. Yes I understand there are certain limitation with certain event fired at the same time but most of them can be avoided (by disable certain component or doing certain condition checking with the event information). Please understand I cant go all the way explain every possible solution to every user so I'll have to prioritise. If you still need more help after, I'm always happy to help you tailor a solution, but that is only I know what exactly you are trying. Even if you are hesitate to let me know the exact application, you can describe the input issue to me without the context of the application.
     
    Last edited: Jul 16, 2013
  35. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38
    Hi songtan, thx for your answer. I'll try to be as concise as possible: we tested the four prefabs mentionned above (double-tap, tap, swipe, swipe rotate) on a plane textured with a map to interact with it. swipe rotate would swipe in translation and double tap would double tap plus one tap. We didn't even think of adding pinch/zoom functionnality...If you have a way, (and i'm sure many buyers will be happy to know) to sort the multi-prefab map without the gestures interfering with each other, i'll be a happy man. I believe we sorted the double-tap before leaving the office. No luck with swipe/swipe rotate so far
     
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    I'm working else where today so I'll have limited access to my usual resource. Until this evening anyway. But I'll try my best.

    First off, why do you have four prefabs running at the same time? One will work just fine. That is how I do it in all the example, most of them require multiple different gestures but only one Gesture prefab is used in each scene. On the subject of interfering gesture, I run a quick test yesterday just to be sure, only gesture of similar nature will fire each event. For instance, a double tap event will fire two tap events, a swipe will result in a drag event fired at the same time, etc. Pinch should be fine for most part unless you enable multi-drag for drag detector.

    Having said that, each gesture fire their own event so they dont really interfere with each other. In practise, you dont normally need that many gesture going on at the same time. Take fruit-ninja, you need tap to click the button and swipe to cut the fruit. Then angry-bird, tap to click the button and drag to pull the catapult. Even in complex RTS scene, like the example name 'RTSCam', you can add in tap to interface with the unit and that's that.

    And I dont recall there being a swipe rotate, just swipe. What is it exactly are you referring to? Fyi, swipe doesnt register any curve or rotation. But what are the difference between a swipe and swipe-rotate in your application? I mean what information do you expect from a swipe-rotate in addition to those in swipe. I'm not sure if it's there (I dont have the documentation with me now) already, but I can add in information like angle of deviation from the initial direction to a swipe event. You can then use that value to determine if a swipe is rotating or not.
     
  37. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38
    Hello I'm off today and tomorrow as well, i'll send you a sample project for you to examine if we don't sort this out ourselves on friday.
    Bye
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Please do. I really like to help. But I cant if I dont know what you intend to use each gesture for.
     
  39. JustDave1961

    JustDave1961

    Joined:
    Jan 5, 2013
    Posts:
    14
    I don't want to argue the point either but for the past 20 years, at least, computers, pda's, touch phones and tablets have all implemented taps exactly as I have described it. Just because you don't agree and there is no standard definition doesn't make you right. You should load up an app/game on any touch device and do as I described before and then try the same with your asset, you'll see that yours works differently.

    Bottom line is that your implementation does NOT work the way every tap in every app/game works on the market that I've used and therefore is useless to me. Your asset is supposed to be an out of the box solution, not something that I should or would want to have to tweak.
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Please dont take this the wrong way. I'm not saying there's a definite right or wrong here, it's just different way of interpretation and implementation. I try to make it so that everything work right out of the box but unfortunately it's simply impossible to accommodate to all the possibility out there. This is why I've left some room to customize the gesture via various parameter on the Gesture prefab. Like I've explained previously, simply changing the 'short tap time' value on the Gesture prefab could change the tap behaviour to what you mentioned.
     
  41. JustDave1961

    JustDave1961

    Joined:
    Jan 5, 2013
    Posts:
    14
    I concede that if I change the "short tap time" value, it works better but causes a different issue.
    If you change the tap time to a higher value (say 100), slide your finger off of the object, remove your finger when it is NOT on the object (either empty screen space or another object), it still registers a tap on the original object. Am I supposed to check which object is touched on the down and up detection or is this just a minor bug which should be easy to fix? I apologize if I came off as gruff or annoyed before, I was just a little frustrated. It seems like it will actually work for me but I do need to know about the issue that I mentioned.

    Thank you for your patience.
    Dave
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    No, thank you for your understanding. I know it could be frustrating at time. :)

    Please bear with me right now as I dont have any documentation or scripts I can refer to. I can only access them this evening. As far as I remember, tap event only fire once - when the finger has been lifted so you only need to check for the object when the event is fired. There should be another variable which allow you to configure the maximum displacement allowed for a tap to be registered (please check the documentation). Meaning any touch which 'slide' over a value bigger than that will be ignored. You can play with that to disable a tap automatically when a finger is 'slide'. The rest is simply checking which object the tap position lands on when the event is fired.

    If your tap is registered despite the finger is displaced by a significant amount, then it's quite possibly a bug. At any rate, I'll check and confirm with your this evening.
     
  43. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    @Dave, I just pm you a package with some modification that will fix the issue you are having. Please check it out.
     
  44. JustDave1961

    JustDave1961

    Joined:
    Jan 5, 2013
    Posts:
    14
    Thank you! Thank you! Thank you!
    The modifications make the Tap work exactly the way I need it!
    Awesome job!

    Dave
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You are welcome!
     
  46. Spartan_Boy

    Spartan_Boy

    Joined:
    Jul 8, 2012
    Posts:
    38
    Hey Songtag, will you update your tap detector in the asset store ?
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    You mean with the recent modification I did for Dave? I'll certainly in the near future. At the mean time, I have some idea that I like to try out first.
     
    Last edited: Jul 19, 2013
  48. Lindrae

    Lindrae

    Joined:
    Jun 13, 2013
    Posts:
    8
    Hi,

    This seems to be what I am looking for! I have been trying to implement the touch behavior by myself but I could not achieve that same smooth behavior I get on PC (mouse). Before I get this asset, is it possible to read the documentation first ? I'd like to be sure that it would answer my needs.
    Lind.
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,990
    Hi Lind, Thanks for your interest. I've just pm you the documentation.
     
  50. JayCrossler

    JayCrossler

    Joined:
    Jul 10, 2013
    Posts:
    10
    I've purchased the framework and am looking to do two things that I didn't see documentation for. Could you point me in the right direction?
    I'd like to:
    1) have many objects (spheres) on screen, and be able to swipe on any of them to rotate them in the direction swiped based on swipe speed. (I wrote a rotator object that I have on the spheres that catches swipes on swipe end, but I'd like one that rotates during the swipe, not just on end).
    2) have a camera that zooms in/out on pinch towards the last object that you tapped.

    Basic idea is to have a solar system that you can zoom around on, and grab planets to rotate them. While the events in the package are good, I'm having to implement a lot of this myself... And think I might be missing something. Thanks!