Search Unity

Input.Touches - Simple Gesture Solution

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

  1. bfarina

    bfarina

    Joined:
    Mar 21, 2014
    Posts:
    6
    You were right about the GUI button, I just assumed it wasnt working because they light up when you hover above them with the mouse and there is no feedback with the touchpad.

    As for the double tap, I have no idea why it doesnt either but thats the case. I just tried an actual build on my iphone and the results were identical as to the unity remote.
     
  2. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    songtan, still appreciating your great asset.

    What needs to happen, so your touch taps do not interact with items behind an active UI? The following is blocking mouse clicks in the Editor, but when I build to iOS the taps get through.
    Code (CSharp):
    1.     void OnMultiTap(Tap tap) {
    2.         if( EventSystem.current.IsPointerOverGameObject()) {
    3.             return;
    4.         }
    5.         // process click/tap
    6.     }
    7.  
     
    Last edited: Jun 20, 2015
    fschneider likes this.
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm very sorry again for the slow respond.

    @bfarina, I'm struggle to see how a single tap works but a double tap does not. They are effectively the same thing. Have you change any of the value on TapDetector? Specifically MaxMultiTapCount and MultiTapPosSpacing? At any rate, try increase the value of MultiTapPosSpacing. That is the most likely culprit of the problem.

    @flyingaudio, what you need is pass the touch index to the function IsPointerOverGameObject(), like so:
    Code (csharp):
    1.   void OnMultiTap(Tap tap) {
    2.     //tap.index=-1 - mousecursor, tap.index>=0 - touchfingerindex
    3.     if( EventSystem.current.IsPointerOverGameObject(tap.index)) {
    4.       return;
    5.     }
    6.     //processclick/tap
    7.   }
    if you are not, the function assume you are testing for mouse cursor, which of course is not the same thing as your finger touch.
     
    fschneider likes this.
  4. essejmclean

    essejmclean

    Joined:
    Feb 21, 2013
    Posts:
    9
    Hi,

    I have an issue that I'm trying to solve.

    I have an energy bar that I want to charge based on the player's touch; the longer they hold down, the more full the energy bar will be. Now I'm using PlayMaker and have been using the 'Input Touches Get Charging Info' action to get information on the length of the hold, but I want the energy bar to expand in real time while the player holds their touch.

    How might I go about achieving this? The action I'm using is only giving me a float variable at the end of the hold/event; it doesn't update every frame, which I want it to do.

    I've noticed that in my console, the charge value is printed every frame. I think that if I could access that and input it into my energy bar, I think that that may work; however, I'm not sure how to access and retrieve it.

    Thanks. Looking forward to the feedback.

    j
     
    Last edited: Jun 30, 2015
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Let me first start by saying I don't use PlayMaker and are not familiar with how it works. So I don't think I'll be very helpful in this case.

    By default, there are three function to provide the charge info. First is when he charge first started, second is when it ends, the third being when it's on-going, where it keeps fire/update every frame. Is there only one way to access the information in the case of PlayMaker? Or is there a way to let it update every frame? Perhaps you can direct this question to the developer of InputTouches. They should be in a better place to answer your question. Since it's they who integrate InputTouches to PlayMaker.

    Sorry for not being able to help here.
     
  6. victor-biosphera

    victor-biosphera

    Joined:
    Jun 21, 2010
    Posts:
    67
    Hi songtan, im getting this error even in your demos scences (orbitcam),you know what it can be?


    NullReferenceException: Object reference not set to an instance of an object
    IT_Gesture.GetDPIFactor () (at Assets/Plugins/InputTouches/IT_Gesture.cs:36)
    DragDetector+<MouseRoutine>c__Iterator1.MoveNext () (at Assets/Plugins/InputTouches/DragDetector.cs:136)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    DragDetector:Update() (at Assets/Plugins/InputTouches/DragDetector.cs:264)
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have to say I don't have the error on my end.

    Looks like for some reason the component 'IT_Gesture' is missing in your InputTouches prefab. Just drag the script (located in Plugins/InputTouches/) to the prefab in your scene, that should solve the problem. Alternatively you can delete the existing prefab and drag a fresh one into the scene.

    Hope this help.
     
  8. takasuto

    takasuto

    Joined:
    May 22, 2014
    Posts:
    6
    input.Touches Are there any way to use in ridibody2d and collider2d?
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sure. You need to use Physic2D.GetRayIntersection() instead of a typical raycast. Like so:
    Code (csharp):
    1.    Ray ray = Camera.main.ScreenPointToRay(point);   //point being the cursor position
    2.    RaycastHit2D hit2D=Physics2D.GetRayIntersection(ray);
    3.    if(hit2D.collider!=null) Debug.Log (hit2D.collider.name);
     
  10. takasuto

    takasuto

    Joined:
    May 22, 2014
    Posts:
    6
    Thank you reply.
    Please tell me a little more gently.
    For example, what happens when the 2D in the case of this description of sample code?

    void OnDraggingStart(DragInfo dragInfo){
    Ray ray = Camera.main.ScreenPointToRay(dragInfo.pos);
    RaycastHit hit;
    //use raycast at the cursor position to detect the object
    if(Physics.Raycast(ray, out hit, Mathf.Infinity)){
    //if the drag started on dragObj1
    if(hit.collider.transform==dragObj1){
    Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(dragInfo.pos.x, dragInfo.pos.y, 30));
    dragOffset1=dragObj1.position-p;
    }

    }
    }
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, for 2D version, the code would have look like this:
    Code (csharp):
    1.  
    2.     void OnDraggingStart(DragInfo dragInfo){
    3.        Ray ray = Camera.main.ScreenPointToRay(dragInfo.pos);
    4.        RaycastHit hit;
    5.  
    6.        //use raycast at the cursor position to detect the object
    7.        RaycastHit2D hit2D=Physics2D.GetRayIntersection(ray);
    8.        //if racycast hits a collider the collider is dragObj1
    9.        if(hit2D.collider!=null && hit.collider.transform==dragObj1){
    10.          //Depends on the setting you are using, following 2 lines might not apply anymore
    11.          Vector3 p=Camera.main.ScreenToWorldPoint(new Vector3(dragInfo.pos.x, dragInfo.pos.y, 30));
    12.          dragOffset1=dragObj1.position-p;
    13.        }
    14.     }
    15.    
     
  12. takasuto

    takasuto

    Joined:
    May 22, 2014
    Posts:
    6
    Thanks.
    It solved.
     
  13. elehelvari

    elehelvari

    Joined:
    Apr 10, 2015
    Posts:
    18
    Hi songtan,

    Should I be worried about this problem of a script missing in your Gesture object? The one at the bottom. See attached image.

    What was that script? Will I miss it? :)
    By the way, there is no error in the console.

    I am installing the latest version of Unity, Playmaker and Input Touches. (Unity 5.1.1f1, Playmaker 1.7.8.3 , Input.Touches 1.2.1)

    Thanks,
    Emese
     

    Attached Files:

  14. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Hi Emese.

    No I don't think it's anything important. All the important script component are there as far as I can tell. You can just remove the component.

    By the way are you sure you are using the latest version? The Gesture prefab you are using doesn't seem the match the one the have. In the current version It has been named "InputTouches" rather than "Gesture". "Gesture" being the name used in older version.
     
  15. flyingaudio

    flyingaudio

    Joined:
    Dec 3, 2010
    Posts:
    98
    @songtan, thanks for your last update v1.2.1. IT_Utility is a great addition.
     
  16. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks, it make sense to add those functions. You have another user Thomas Crown to thank for giving me the idea. :)
     
  17. elehelvari

    elehelvari

    Joined:
    Apr 10, 2015
    Posts:
    18
    I was using the latest from the asset store but I see now that since yesterday there is a newer version.
    After updating I found the problem: Your playmaker example scenes have not been updated, they still contain the Gesture object, which is red and "missing" now.
    Your demo scenes, on the other hand, correctly have the InputTouches object instead.

    Br,
    Emese
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Hi Emese,

    Thanks for the note. For your information, the playmaker side of InputTouches is managed by the playermaker team. I don't really have access to it's source so that's really not much I can do. Anyway, I've informed them about the new update so hopefully they will apply the new changes soon.

    Song
     
  19. ptblk

    ptblk

    Joined:
    Mar 27, 2015
    Posts:
    57
    Really wish you devs would start to understand that peoplewho buy these assets ARENT CODERS! That is why we come to the asset store and buy from you. I have ZERO idea how to get this to work and ZERO tutorials from you. So now i sit with an asset with folder and a bunch of scripts. I want a plug and play solution so that i can implement it into my app. Why is this so hard to understand. Create a UI to link game object and required motions into. THAT is a PROPER ASSET!
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sorry that you are upset. I certainly understand your frustration when stuck trying to get certain things done.

    But please understand that this is not a visual scripting tool. It's a scripting package intended for user who knows how to code. In fact I've explicitly state that coding skill are required to use the package in the package description. There's a documentation contain instruction how to use the it, not to mention example scene with commented scripts. It's for all intend and purpose, a 'proper' asset for right group of users. I believe the amount of positive review given to this asset is a testimony to that.
     
    theANMATOR2b likes this.
  21. elehelvari

    elehelvari

    Joined:
    Apr 10, 2015
    Posts:
    18
    Yes, this is a great plugin and I managed to get it working together with playmaker without any coding knowledge.
    I am sure I could do much more with it if I knew how to code but what I managed is just enough right now. Keep up the good work and thanky you songtan for a useful plugin and especially for great support and keeping it up to date.
    ptblk, check out the playmaker example scenes. If you are using playmaker (since you are not coding, I guess you are) than those will help to get started.
     
    theANMATOR2b likes this.
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    @elehelvari, Thanks for the vote of confidence. :)

    @ptblk, just as elehelvari said, perhaps you should give playmaker a try if you haven't already. I'm not sure if it's going to be totally pain free as there maybe some learning process involved, but it's very good solution for people who don't really want to deal with coding.
     
    theANMATOR2b likes this.
  23. takasuto

    takasuto

    Joined:
    May 22, 2014
    Posts:
    6
    Drag an empty space on the screen by tapping with finger.

    Specific object on the screen, the distance minute movement to move the finger.

    Can you easily with 'input.touches'?
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I cant quite understand what exactly are you trying to do there from what you have describe. Drag a selection zone using the finger input? Get the distance of the finger position to a certain object?

    I can't comment on how easy they can be implemented. Please understand the package only gives you a way to detect the inputs, it's up to you to implement the rest. Suffice to say in most case you will have all the information (say the input's position, speed, duration, direction, etc) to do what you need. It saves you the effort to have an extra layer of code to get these information, but the rest is up to you. With that said, I suppose what you are suggesting can be done. However how easy it's will depends on how comfortable you are with coding.
     
  25. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    how can i test IT_Gesture.onTouchDownE in Unity editor? it works on tablet.
     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, as the name suggested, it can only detect touch. Not mouse click. The only way to get test it in editor, as far as I know, is using UnityRemote.
     
  27. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    how can i use InputTouches with new GUI? i use second camera for canvas. hit.collider is null.

    private void ProcessUpEvent(Vector2 pos)
    {
    //Vector2 worldPoint = Camera.main.ScreenToWorldPoint(pos);

    Vector2 worldPoint = _uiCamera.ScreenToWorldPoint(pos);

    //Debug.Log("ProcessUpEvent");

    RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero);
    if (hit.collider == null)
    return;
    if (hit.collider.gameObject.name == "ButtonUp1")
    {
    _racketController1.KeyUpClicked();
    }
    else if (hit.collider.gameObject.name == "ButtonDown1")
    {
    _racketController1.KeyDownClicked();
    }
    }
     
  28. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    What are you trying to do exactly. Try to detect touch on the UI?

    Try look into the script IT_Utility.cs. I have some function there that could help you to detect object of various kind, including UI object. I think the specific function you are looking for is IT_Utility.GetHoveredUIElement. Just pass the cursor position to it and you should get the UI object the cursor landed on.
     
  29. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    i try to detect touch down and up events on a gui element. i tried you function. i have a button with image and a child with another image object.you function finds child image object. i will examine your function to find root button object.

    Edit:raycastResults has 2 results. raycastResults[1] is what i want. i changed z pos but result is the same.
     
  30. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can try add a CanvasGroup component to the object you don't want the cursor to detect and uncheck the block raycast flag. That should prevent the object from being picked up by the raycast.
     
  31. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    Thanks songtan, what you suggest works great !
     
  32. Lindrae

    Lindrae

    Joined:
    Jun 13, 2013
    Posts:
    8
    Hi all !
    I've been using this asset for quite some time now, and I am still enjoying it !

    I am now looking into WebGL builds for PC. On this platform, input.Touches works like a charm, except (yeah here it comes!) that I encountered an unusual behaviour of the DoubleTap detection : the right mouse button double-click is perfect, whereas the left one does not work as intended.
    Example : in the TapDemo scene built as webGL,
    - a left double-click triggers the DoubleTap event sometimes IF the mouse isn't moved at all during clicking. I couldn't find the condition to replicate it at 100%.
    - a left double-click can trigger a Dragging Event : I tried it on the "Drag Me" balls with positive results. This happens almost everytime I tried it.
    - a right mouse button double click triggers the DoubleTap event every time and never triggers a dragging event.

    I have been playing around with the MaxTapDisplacement, MultiTapPosSpacing and MultiTapInterval with no interesting results. Not really surprising since everything works normal with the right mouse button...

    Also, everything works normally in the Editor, obviously... It would not be fun otherwise ;)

    Any idea where to look ?
    Cheers,
    Lind
     
  33. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Interesting... I've just run a quick test. I have to say I haven't encounter what you described. But I was using Unity5.0 and onMultiTap so I'm not sure if that could be the difference.

    On that note, are you using the latest version of InputTouches? DoubleTap has been replaced with onMultiTap a few update ago (quite a long time ago in fact). I haven't been testing/using DoubleTap myself since then. I would suggest you to switch it to onMultiTap and see if the problem persists.
     
  34. Lindrae

    Lindrae

    Joined:
    Jun 13, 2013
    Posts:
    8
    Problem solved after a quick discussion with Songtan : it was a Unity 5.1 bug.

    Upgrading to 5.2 made everything back to normal again.
    This is what was going on : link found by Songtan
    Thanks again !
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are welcome. :)
     
  36. habsi70

    habsi70

    Joined:
    Jan 30, 2013
    Posts:
    25
    Hi,

    I am currently using Input.Touches in a quite simple project. I need to detect touchdown/touchup to initialize/reset some settings and the onDragging event to, as you might guess, drag objects.

    This works fine on my macbook pro with unity remote. When I test the same unchanged scene on a windows machine with a touch screen (in unity editor and the compiled app) the touchdown/touchup events are not fired. Dragging works fine.

    Because Input.Touches is for me the most accessible and flexible touch library on the store I would like to continue using it on windows too. Is there maybe a special setting for Windows or does anybody else have this problem?

    Thank you and greetings
    habsi
     
  37. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    What exactly is the platform and touch screen you are using on window? A window touch monitor? Or on Android Remote?

    There is a slight problem if you are using a normal touch monitor. The reason is InputTouches only uses default Unity touch library. As far as I'm concern, that doesnt support all the touch monitor. Perhaps you can try to detect mouse input instead of touch (using mouseDown/mouseUp). Most pc touch screen emulates touch control as mouse so with some luck it should work.

    Hope this helps.
     
  38. habsi70

    habsi70

    Joined:
    Jan 30, 2013
    Posts:
    25
    Hi songtan,

    using the mouse events solved the problem, thank you! I did not think that you implemented Mouse Events. Always learning something new ;) Thank you for your fast reaction and the great library you created!

    Greetings
    habsi
     
  39. Ylor

    Ylor

    Joined:
    Dec 15, 2014
    Posts:
    16
    Hi!

    I'm using Input.Touches for my project. I use it to move the camera around in a room. There is also a UI-frame with buttons in screenspace wich are always available to the player. My problem is, touches on the UI-buttons are also registered by Input.Touches so that the camera sometimes moves around when interacting with the UI. Before I start experimenting on my own, I'd like to ask, is there a simple solution for this?

    Best regards,
    Rasmus
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes there is. Check the functions in IT_Utility.cs. Those functions there that could help you detect various in game object, UI elements included. What you can do is use IT_Utility.IsCursorOnUI() to check if the cursor has landed on a UI object in your event callback. Like so:
    Code (csharp):
    1. void OnTouchDown(Vector2 cursorPosition){
    2.   //if the cursor is on a UI element
    3.   if(IT_Utility.IsCursorOnUI(cursorPosition)) return;
    4.  
    5.   //carry on with the rest of the code
    6. }
    Hope this help.
     
  41. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    @songtan thanks for the hint, however it is not completely working for me. In the SwipeHandler it works, in the SwipeEndHandler not. Do you have any idea about this?
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure which issue you are referring to. I'm going to take a guess that it's the one with IsPointerOverGameObject()? I cant see how it works in one function but not another, if you are doing exactly the same thing. Can you explain what exactly are you doing and in what way it doesn't work?
     
  43. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    Yes, exactly. EventSystem.current.IsPointerOverGameObject would return false in a swipe end handler.

    Code (CSharp):
    1. private void OnSwipeStart (SwipeInfo sw)
    2. {
    3.       if (EventSystem.current.IsPointerOverGameObject(sw.index)){
    4. ...
    5.        }
    6. }
     
  44. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    @songtan : What is the difference between a DragHandler and a SwipeHandler?
     
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not sure but my guess is the finger has already been lifted from the screen after the event is fired. Thus when you call the function it return false. I would suggest you use the function in IT_Utility instead. Those are position based and universally applicable to both mouse or touch input. For what you need, something like this would do:
    Code (csharp):
    1.  
    2.   void OnSwipeStart(SwipeInfo sw){
    3.      if(IT_Utility.IsCursorOnUI(sw.startPoint)){
    4.        
    5.      }
    6.    }
    7.    void OnSwipeEnd(SwipeInfo sw){
    8.      if(IT_Utility.IsCursorOnUI(sw.endPoint)){
    9.        
    10.      }
    11.    }
    12.  
    dragHandler and swipeHandler is very similar except that swipeHandler has to full fill some criteria before it's considered a swipe. They are things like the movement speed of the cursor, the duration of the cursor on screen, directional change, etc. Basically the configuration you see on the SwipeDetector component.
     
  46. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    Hi songtan, do you plan to support Apple TV siri remote? I haven't tested input touches with tvos yet. maybe it works now :)
     
  47. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately I don't have plan for that. It's very unlikely to happen if I'm honest as I myself is not a keen user of apple product. I don't have the hardware even if I want to.
     
  48. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    @songtan I currently do not see IT_Utility although I have imported the InputTouches.prefab
    Do I need to import more of your package? I decided not to import the demo stuff.

    If that is not the problem, maybe updating InputTouches failed. How can I check what version of your plugin I am having?
     
  49. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can open AssetStore window download tab in unity editor (a small download icon on top left corner) to check if your local copy of InputTouches is up to date. Either way you can just download it again to make sure. Once it's up to date, you can try to import that package again. IT_Utility.cs should be there even though you didn't import the demo. It's in "Plugins/InputTouches" folder.
     
  50. fschneider

    fschneider

    Joined:
    May 26, 2014
    Posts:
    42
    It seems my Unity installation is maintaining a cached, but old version of the package. Whenever I hit the import button, I only get the package contents of an outdated version of InputTouches, without IT_Utility.cs
    Btw, sorry for asking the superfluous question where that file would be located :) I did not check the "Package Contents" list on the Asset Store.