Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Input.Touches - Simple Gesture Solution

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

  1. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    You a re abolutely right, PinchInfo is something I added in the last update. Still keep remembering the old way.
     
  2. saifis

    saifis

    Joined:
    Oct 11, 2013
    Posts:
    6
    hi, I've been attempting to build on top of the orbit example, and have been trying to add camera pan to it,this has proven to be more difficult than I had foreseen since the orbit script depends on the center coordinates( x and y) to be still, I wish some assistance on which way I should go, to start from scratch or keep digging at the current code.

    what I have done is,

    1.moved orbit to two finger gestures, they work fine,
    2.using single drag to get the delta distances as so,
    My problems starts from here,
    I attempted to stick the panSpeed Vector2 variables into the arguments for positions, but ofcourse they get reset at the beginning of the Update method for calculations. I have tried

    a. Setting the x and y coordinates to center at the end of update, which semi works, but seems to mess up the orbit and zoom,
    b. comment out the
    so calculations do not get out of sync, but this also affects other movements.

    Sorry if I am asking elementary questions, I am new to the concept of 3d, any help is appreciated, if you need sample code, I would be happy to create a sample project.
     
  3. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Hi saifis,

    I'm not really sure what are you trying for. Are you trying to add movement to the OrbitCam like how it's in RTSCam? So you say you are trying to use single drag to get delta distance, but delta distance of what? From the code it seems that you are trying to move the pivot of the camera but then again you also tried setting the x and y coordinates to center (which I assume 0, 0, 0?) ? So I'm quite confuse.

    If you wants to move the pivot point of the orbitCam. I would recommend you to look into implementation of RTSCam. The camera is placed under a empty parent object which used as a pivot point. You can safely move the pivot point by moving the parent transform easily without messing up the orientation and zoom.

    At any rate, please explain what exactly do you need so I can help.
     
  4. saifis

    saifis

    Joined:
    Oct 11, 2013
    Posts:
    6
    Thanks for the quick response.
    I wanted an example script so I could make a basic touch camera app that could pan, orbit and zoom in out.

    And yes the RTS cam is exactly what I needed, sorry I missed that demo.

    Now all I need to do is clamp the rotation and pan area of the camera.

    Thanks again, this will save me much time. Your asset is worth every penny.
     
  5. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Excellent, glad you find it useful!
     
  6. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    565
    Are the Gesture.OnMouse* events working in the latest build? I just upgraded my Input.Gestures installation from the Unity store, but the OnMouse events don't seem to fire (on a PC, using a mouse) in my code.

    Looking, the supplied demos that use these events don't work either. For instance, the DPad demo seems to be non-functional.

    (FYI - I posted this message on the Input.Gestures website also.)

    Jeff
     
  7. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Hi Jeff,

    Thanks for letting me know. Yes it's not working at the moment and I'm aware of that. Some one has just informed me about it yesterday. It's due a small error on my end. I added some additional logic (not sure why I done it in the first place) and seems to have broken it. It's very easy to fix, just remove line23 line31 on BasicDetector.cs and that should be it.
     
  8. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    565
    Thanks for the quick reply. Yeah, I noticed that the mentioned compiler directives looked problematic for my use-case, but thought I'd wait on your input before making any changes. Anyway, removing the directives has things working as expected.

    Thanks again.

    Jeff
     
  9. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    There is a huge problem with this library. It is not framerate independent. I'm implementing something similar to Bioware's "pause time and plan" mechanic. InputTouches using Time.time to do all the calculations instead of creating it's own delta time by taking realtimeSinceStartup:

    http://docs.unity3d.com/Documentation/ScriptReference/Time-realtimeSinceStartup.html

    Its my own fault for using a third party library. But this is a MAJOR flaw for anyone manipulating time. The library becomes completely non functional for anything other than clicks.
     
  10. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    i fixed this by simply replacing all references with Time.time to Time.realtimeSinceStartup.

    you should roll this into your next release!
     
  11. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Thanks so much for the feedback, you are absolutely right. I never thought of usage of time scale manipulation at any point when I write the code. I'll fix that asap and do an update.

    Awfully sorry for your inconvenience.
     
  12. GlennoOZ

    GlennoOZ

    Joined:
    Jan 9, 2014
    Posts:
    3
    Would this be a good plugin to recognise/detect custom gestures, such as circles, squares, and user defined shapes, etc. Or is that outside the scope of Input.touches?

    Ive purchased it for its touch input functionality, but am also wondering if it can recognise custom, complex gesture shapes.

    Thanks in advance
     
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Thanks for your purchase. Unfortunately you can only detect pre-determined gesture using InputTouches. And they are of the generic ones like multi-tap, swipe, pinch. It doesnt support advance gesture like shapes or alphabets. Apologise for the short-coming.
     
  14. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    Hello

    Is it possible to use your system to handle iOS native touch events from within a unity script in c#?

    I'm trying to get notified directly from iOS when a finger move across the screen because Input.GetTouch() in unity drops messages under certain situations.

    I was hoping that by using your sytem I'd be able to provide my own handler so I can process **all** touch events that iOS generates.

    is such a thing possible with your plugin?

    thanks.
    -nacho.
     
  15. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Unfortunately I dont think that is possible. The plugin itself uses the unity Input library only and no other external dependency.
     
  16. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    40
    ok, got it, thanks for the reply.
     
  17. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    My question is, how do I stop touches being propagated to your Input.Touches when it ends up being just a simple click on a NGUI element. for example i can start a pinch gesture even though one touch is on one of the ngui ui elements ?
     
    Last edited: Jan 16, 2014
  18. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    A solution I used for this issue is to do a raycast using the touch position and see if the touch landed on any GUI element before executing the code any further. You can use something like this for NGUI:

    Code (csharp):
    1.  
    2.     public Camera uiCam;        //the camera used to render the NGUI objects
    3.     public LayerMask uiMask;    //the layer used by of the NGUI objects
    4.     bool IsCursorOnUI(Vector3 point){
    5.         // pos is the Vector3 representing the screen position of the input
    6.         Ray inputRay = uiCam.ScreenPointToRay( point );    
    7.         RaycastHit hit;
    8.  
    9.         if( Physics.Raycast( inputRay, out hit, Mathf.Infinity, uiMask ) ){
    10.             // UI was hit
    11.             return true;
    12.         }
    13.        
    14.         return false;
    15.     }
    16.  
    In the input code, you can simply call the function to check:

    Code (csharp):
    1.  
    2.     void OnTap(Tap tap){
    3.         if(IsCursorOnUI(tap.pos)) return;
    4.        
    5.         //input is not on any GUI elements, execute the rest of the code       
    6.     }
    7.  
    Hope this help.
     
  19. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    Yeah for taps and such things this works. but what about for example dragging. when the user starts a drag on a ui element (a click) and moves the finger away this is triggering dragging events. now i thought i could catch this via using your technique in a onDragStart event and set a member in the drag info to cancel this drag event but this is not supported.

    what suggestion do you have for this case ?
     
  20. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    I'm not sure how exactly does your application work so it's hard to tell. Does your code goes into onDragging or onDraggingEnd? If the former, you can use exactly the same method. If the latter, I would do what you suggested, set a flag in onDragginStart and check the flag in onDraggingEnd. You dont need to access to the dragInfo, with each event fired the dragInfo past is a new instance. What you can do instead is create a bool in your script, like so:

    Code (csharp):
    1.     bool cursorOnUIFlag=false;
    2.    
    3.     void OnDraggingStart(DragInfo dragInfo){
    4.         if(IsCursorOnUI(dragInfo.pos)){
    5.             cursorOnUIFlag=false;
    6.             return;
    7.         }
    8.        
    9.         cursorOnUIFlag=true;
    10.     }
    11.    
    12.     void OnDraggingEnd(DragInfo dragInfo){
    13.         if(!cursorOnUIFlag) return;
    14.         if(IsCursorOnUI(dragInfo.pos)) return;
    15.        
    16.         //insert custom code
    17.     }
     
  21. Extrawurst

    Extrawurst

    Joined:
    May 22, 2013
    Posts:
    43
    not nice but doable..
    too bad your lib does not support this generically, i whised i could just add a ui click check callback once anywhere and do the raycast there ...
     
  22. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    I wish I could. However there's is no one size fits all solution for this issue. Different GUI implementation require different work around so it's difficult for me to try to cover it all. The raycast method only works for certain kind of UI only. The Check-Cursor-On-UI function only works for specific setting of NGUI only, even something like adding additional UI camera might break the code.

    So regretably I'll just leave it for the user to decide how best to go around it.
     
  23. tressix

    tressix

    Joined:
    Sep 4, 2013
    Posts:
    1
    What's the difference between the drag and swipe gestures? I've read through the documentation pdf but it doesn't seem to point out what constitutes a swipe vs drag.
     
  24. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Indeed, both are very similar. The differences is that swipe has some specific condition check (speed, direction, time). For a swipe input to be valid and the event got fired. The finger movement has to be above certain speed, kept at a certain fixed direction, and takes no more than a certain time duration. Drag on the other hand, has none of the limit. Hope this clear things up.
     
  25. BossHoss

    BossHoss

    Joined:
    Jan 19, 2014
    Posts:
    3
    I am leaning towards buying this. One question, does it fully support 2D games/apps?
     
  26. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    It's not intended for any specific application, 2D or 3D. It's just a generic input gesture detection. As long as user is doing the match input, it fires the corresponding event, giving the relevant value. So the nature of the game/application has nothing to do with it. As long as you can have the input value, you are free to interpret it for 2D or 3D purpose.
     
  27. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    A quick anouncement: I'll be away and traveling for the next two weeks starting tomorrow. Obviously I wont be as readily available as I currently am. So my apologize in advance for the slow respond to any potential question/issue.
     
  28. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,042
    i have a multitouch application. it looks when i tab 2 points it behaves like i tapped in the middle of these points. i am not sure if it is related InputTouches. how can i solve this problem?
     
  29. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    I'm not really sure what's the problem here, so you do a tap with 2 fingers or do you do a double tap on two different positions? In both case, the position registered will be the middle. If you can explain what you are trying to do and show me your code. I could probably give you some pointer what to do.
     
  30. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,042
    i think it is known problem reported here;

    http://forum.unity3d.com/threads/10...uch-problem-(3rd-touch-added-after-2-touches)

    i have a button on my screen.instead of tapping on the button i tap with my 2 fingers by equal distance to button. unity process it as it is clicked in the middle. so onmousedown works. i think solution is to get tab points and raycast it to get button collider if it is tapped, like your demo scene TapDemo. is there any solution?
     
  31. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
  32. saifis

    saifis

    Joined:
    Oct 11, 2013
    Posts:
    6
    I have an issue where the method I assign to onMultiTapE gets called twice. Things I have checked,

    -If I have added the script responsible for it multiple times,
    -assigned onMultiTapE multiple times
    -tried the now obsolete OnShortTap
    -tried it on touchscreen and mouse

    No matter what I do I have the event firing twice every time I tap or click, this is very problematic because I want to have an object selected when tapped, and deselected when I tap it again. I have tested the TapDemo and there is no problem there, so its definitely something on my end, but I am clueless at how to fix the problem at this point. More odd since the snippet of code is practically copy and pasted from the Tapdemo.

    The code goes,

    Code (csharp):
    1.     void OnEnable(){
    2.         Gesture.onMultiTapE += OnMultiTap;
    3.     }
    4.    
    5.     void OnDisable(){
    6.         Gesture.onMultiTapE -= OnMultiTap;
    7.     }
    8.  
    9.     void OnMultiTap(Tap tap){
    10.         //do a raycast base on the position of the tap
    11.         Ray ray = Camera.main.ScreenPointToRay(tap.pos);
    12.         RaycastHit hit;
    13.         if(Physics.Raycast(ray, out hit, Mathf.Infinity)){
    14.             if(hit.collider.transform.name =="TARGET_OBJECT"){
    15.                 if(  NOT SELECTED){
    16.                     SELECT
    17.                 }
    18.                 else if ( SELCTED )
    19.                                      DESELECT
    20.                 }
    21.             }
    22.         }
    23.     }
    24.  
    Any help in the right direction would be super helpful, thank you in advance.
     
  33. Mikael-Madrid

    Mikael-Madrid

    Joined:
    Nov 2, 2012
    Posts:
    26
    Hello and thankds in advanced!,I bought the plugin months ago but I havent needed to use it until now.
    Is there a "permamente charging" state?,When using the charging-touch after about 1 second the charge ends on its own even tho ive kept the finger "down". Thanks again.
     
  34. Mikael-Madrid

    Mikael-Madrid

    Joined:
    Nov 2, 2012
    Posts:
    26
    Answering myself I just realized the "Gesture" gameobject has different settings,including "clamp" for charging so it doesn't end prematurely.
    Great plugin! ;)
     
  35. saifis

    saifis

    Joined:
    Oct 11, 2013
    Posts:
    6
    Answering myself too, thanks to Mikael I've figured out the problem, the answer for my problem was also in the Gesture object, for some reason I had added another tapdetector in there, which was causing the tap to be detected twice.

    Ashamed of the stupid mistake I have made.
     
  36. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Sorry guys for the slow respond. Seems like you guys have found the solution that I would have said. :)

    Btw I'm now back to work and should be available most of the time.
     
  37. Deleted User

    Deleted User

    Guest

    Hi

    I bought the addon, but seem to be having some trouble.

    I would like to know when a finger is pressed down, the position and the id, likewise when the finger has moved and released.

    However I can't see a way to do this. The drag detector can do this, but I need to move the finger at least 1 pixel for that to trigger.

    the basic detector has OnTouch(touch.position) onTouchDown(touch.position), but doesn't give you the ID of the finger.

    Any thoughts?

    Thanks
     
  38. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    I can do some slight modification so that you get the finger-ID with onTouchE and onTouchDownE. Please send me an email so I can send you the code when I'm done.
     
  39. Matt-Face

    Matt-Face

    Joined:
    Mar 24, 2013
    Posts:
    18
    Hi Song,

    I have just purchased Input.Touches.

    Where can i find the documentation for this package?
     
  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Thanks for you purchase. The documentation should have been included in the package. A PDF file. Please look inside the folder InputTouches.
     
  41. hgaur725

    hgaur725

    Joined:
    Feb 20, 2014
    Posts:
    17
    hii . songtan can u help me out
     
  42. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Well, sure I'll try help if it's InputTouches related. But I cant help if you dont state what's the problem.
     
  43. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    Wondering if you had any thoughts on what I'm trying to accomplish. I'm currently using the unity joystick prefab with a guiTexture for my character movement. I've converted all my buttons over to use your touch events in a separate script. Right now I can't both move the character and shoot at the same time. Is it at all possible to get a joystick working with the touch events from your package, similiar to the Unity joystick prefab?

    Edit: I was thinking maybe using the OnCharging to get the input pos for the joystick with a rect, wasn't sure if OnCharging would be the right thing to use though.
     
  44. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    I'm not sure how ur control scheme work exactly. I assume finger drag on the joystick to move and short tap to shoot? I would use onTouchE to detect touch for the joystick and onMultiTapE for shooting. You should be able to use them concurrently.

    Sorry to have give such a brief answer but I'm away from home these few days so I dont have access to my normal pc. If you need more pointer please let me know. I'll try to explain in greater detail.
     
  45. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    You are correct, I am using onShortTapE to detect firing button touches. My joystick script currently loops through the touches on it's own, compares the fingerID, and tracks the touch if it matches. I was hoping to roll a new joystick using your touch library so everything is controlled together. I will look into the the suggestion you made and see if I can get something working, thanks!

    On another note, I just updated from ver 1.0 to the latest version (to get access to the new event types), and I am now getting two errors in Unity:

    Assets/Plugins/InputTouches/General.cs(37,17): error CS0246: The type or namespace name `InputEvent' could not be found. Are you missing a using directive or an assembly reference?

    Assets/Plugins/InputTouches/General.cs(41,25): error CS0246: The type or namespace name `_InputState' could not be found. Are you missing a using directive or an assembly reference?


    Any suggestion on how to resolve these errors?

    Thanks for your help and prompt responses!
     
  46. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    Hm... I'm not sure what went wrong there. I can check since I don't have access to my pc. Have try on a fresh import? I mean by deleting all of current inputTouches files n re-import?

    I could check it out but you would have to wait until wednesday.
     
  47. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    That did the trick, thanks!

    Another question, if I may?

    I am trying to use onTouchE event for my joystick, but it looks as though that event only passes the pos variable. How can I detect a touch (that continues to send events while it's down), and get access the the tap class?

    Sorry, I am still trying to wrap my head around some of this stuff.
     
  48. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,625
    The best event to use in your case would still be onTouchE. I can do the modification so that it provides additional info other than the position. But you will have to wait a bit. Is there anything else you need other than the touch ID?
     
  49. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    I believe all I would need is the touch ID. No worries on the wait, greatly appreciate your help.
     
  50. MythicalCity

    MythicalCity

    Joined:
    Feb 10, 2011
    Posts:
    410
    Hi there, I have 2 questions about the plugin if you have a second:

    1) Is there any sort of NGUI support out of the box? or do I have to code in a layer filter to filter out the NGUI touch events?

    2) Is there support for standalone windows builds on windows tablets that have touch support? (not Win8 store, just windows desktop standalone builds).

    Thanks for your time!
     
unityunity