Search Unity

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,993
    @NyxPixel1, please send me an email so I can send you the modified code.

    @capitalJmedia, Sorry for the slow respond. I was away for the past 2 days. Now to answer your question.

    1. I'm afraid there's no NGUI support out of the box. So so you will have to code an extra filter. It's pretty simple, you can do it on the event receiver's end of InputTouches.

    2. I'm not sure tbh. I dont have the means to test it. The rule of thumb is, if Unity's default touch/mouse input class works on the platform, it should work. You can do a simple test on your own device, see if the build on the device can picks up input event like if(Input.GetMouseButtonDown(0) or if(Input.touchCount>0). If it can, then InputTouches should works.
     
  2. GlennNZ

    GlennNZ

    Joined:
    Jul 16, 2013
    Posts:
    5
    I'm still investigating this, but it seems that OnMFDragging and OnPinch don't fire at the same time. So if I'm doing a multi-finger drag event while at the same time changing the distance between the two fingers, then all I'll get is a pinch event.

    If what I'm seeing is indeed the case, that makes doing things like map panning and zooming at the same time more difficult. I'm having to start bringing in unity touch events such as:

    if (Input.touchCount == 2)
    {
    Vector2 pos1 = Input.touches[0].position;
    Vector2 pos2 = Input.touches[1].position;
    StartPan( pos1 + ((pos2 - pos1) / 2) );
    }

    which is unfortunate, because it would be good to use all the event handling logic from one library.

    Is there something I haven't configured? Two finger panning works really well just by itself, but as soon as I handle an onPinch event and that event fires, it does so at the expense of OnMFDragging.
     
  3. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    No, unfortunately OnMFDragging and OnPinch don't work simultaneously. See how you classified a 2-3 fingers drag if the distance between the finger is changing all the time? It could well be mutiple single-finger drag event. Hence relatively consistent distance between the fingers are one of the condition required for a MF-Drag event. On the other hand, OnPinch requires constant distance change between 2 fingers to work. So in my interpretation they are mutually exclusive.

    However there might be a work around. But even I'm a bit unsure of this. You can remove the finger's distance condition check required for MF-drag. In this case, obviously the individual fingers wont be needing to move in the same direction anymore. The question is would the drag direction still consistent enough to be useful? It may work for a two fingers drag, but anything more would be a big unknown.
     
    Last edited: Mar 17, 2014
  4. GlennNZ

    GlennNZ

    Joined:
    Jul 16, 2013
    Posts:
    5
    I'm surprised there is a finger distance check for MF-drag. If it was a two finger drag (I'm not sure what would be done for 3 fingers), wouldn't the direction of the drag be a vector formed from the previous mid point of the two fingers to the current midpoint of the two fingers? If the distance between the two fingers changed, then this would also cause a pinch event.

    I'm trying to compensate by starting a drag (i.e. doing the initial raycast) when there is a two finger tap (by using Unity event code), and then performing a drag by taking the mid point of the pinch event points in order to drag and pinch at the same time. I think I've stuffed something up with my code though; still working on it, but the logic seems sound.
     
  5. Shirts

    Shirts

    Joined:
    Nov 4, 2012
    Posts:
    8
    Hello Songtan,

    I bought Input.Touches and for the life of me I'm struggling with this problem:

    I'm trying to divide the screen into two invisible multitouch "buttons". I want Side A to perform ActionA and Side B to perform ActionB. And also they need to be pressed simultaneously if need be.

    Any help appreciated, thanks.

    -j
     
  6. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You are right. The direction of the drag would be the vector formed from the previous mid point of the two fingers to the current midpoint of the two fingers. The pinch on the other hand, measure the relative movement vector of the 2 fingers. Hence when the distance of the finger is not fixed when doing a two-fingers drag, pinch will be fired.

    Your improvisation seems sounds fine to me. The catch would be you will need to move your two fingers in opposite direction all the time, while drag both of them across the screen at the same time. If you just do a pinching motion, there wouldnt be any movement for the drag. But if you stop pinching for a split second when you drag, the pinch event wont fire at all so your drag function wont be call either.


    This is a relatively easy issue to solve. Try this:
    Code (csharp):
    1.  
    2.     void OnMultiTap(Tap tap){
    3.         if(tap.pos.x<Screen.width/2){
    4.             //the tap is on the left hand side of the screen
    5.         }
    6.         else if(tap.pos.x>=Screen.width/2){
    7.             //the tap is on the right hand side of the screen
    8.         }
    9.     }
    10.  
     
  7. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    Hey Songtan,

    Another question here, tried searching but didn't see it answered anywhere already. I am using box colliders and raycasting to detect if my button is being pressed. This is working fine with the short tap for single firing weapons. I am currently trying to use the input to work as a flamethrower type mechanic. It works great using "onCharging" to turn the weapon on, and "onChargeEnd" to turn it off. The issue I am having is that "onChargeEnd" is firing if I move my finger/mouse in the slightest, without actually removing it. Any idea why this would occur, or how to work around it?

    Thanks!

    Edit: I am instead trying to use onMouse1E and onMouse1UpE, but using the editor neither one of these events seem to fire (I never see either of the debug log statements). Not sure what I am doing wrong, here is the code:

    Code (csharp):
    1.  
    2.  
    3. function OnEnable()
    4. {
    5.     Gesture.onMouse1DownE +=OnMouse;
    6.     Gesture.onMouse1UpE +=OnMouseUp;
    7. }
    8.  
    9. function OnDisable()
    10. {
    11.     Gesture.onMouse1E -=OnMouse;
    12.     Gesture.onMouse1UpE -=OnMouseUp;
    13. }
    14.  
    15. function OnMouse(pos : Vector2)
    16. {
    17.     Debug.Log("mouse on" + counter);
    18.     var cursorRay : Ray = GUICamera.ScreenPointToRay(pos);
    19.     var hit : RaycastHit;
    20.     if( Physics.Raycast( cursorRay, hit, 1000.0f) )
    21.     {
    22.         if(hit.collider.transform == fire1)
    23.         {
    24.             fire.Fire1(1);
    25.                 }  
    26.          }
    27. }
    28. function OnMouseUp(pos : Vector2)
    29. {
    30.     Debug.Log("mouse off");
    31.     var cursorRay : Ray = GUICamera.ScreenPointToRay(pos);
    32.     var hit : RaycastHit;
    33.     if( Physics.Raycast( cursorRay, hit, 1000.0f) )
    34.     {
    35.         if(hit.collider.transform == fire1)
    36.         {
    37.             fire.Fire1(0);
    38.         }
    39.         }
    40. }
    41.  
     
    Last edited: Apr 12, 2014
  8. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    This is to prevent confusion with drag event, which is holding the finger/cursor and move around, while charge event is meant to have the cursor stay in the same spot. So there's a check for the cursor movement for charge event, whenever it has move past a specified magnitude, the charge event is terminated and thus onChargeEnd is fired. You can change this by edit the threshold value. Try change the value of tapPosDeviation in TapDetector.cs, line 79. If you dont want this to be a factor at all, set it to a big value such as 99999. That should remove the restriction.

    Hope this help.

    Edit: For the onMouse1E and onMouse1UpE, have you enable BasicDetector on the Gesture pefab?
     
    Last edited: Apr 12, 2014
  9. NyxPixel1

    NyxPixel1

    Joined:
    Apr 5, 2013
    Posts:
    15
    Ah, both of those suggestions worked, thanks so much!
     
  10. Silverfell

    Silverfell

    Joined:
    Aug 29, 2013
    Posts:
    5
    I'm having an interesting issue with OSX Web Player builds.

    The project I'm working on uses AABB boxes quite extensively to drive interface interactions. I'm using the default Gesture prefab, loaded in my scene, and never unloaded/removed. Everything works fine, until I test the web player build of the game in OSX.

    No matter what the browser (I tested both Chrome and Safari), the first time I load a new build of the project, Tap.pos is registered as (Infinity, Infinity). If I refresh the browser, and the build reloads, this never happens again. The debug output I am receiving is baffling, as the mouse detects the taps properly.

    Before I start tearing into code and builds, what could cause GestureOnOnMultiTapE to return a Vector2 with both values set to Infinity?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    This is interesting. I've checked and as far as I can tell, the only instance where this could be happening is when you are using touch input with multiple finger. Even then the code logic would allow that to happen. If you are interested, the code is in PublicClass.cs, Tap class constructor for multifinger tap, where the pos is divided by the finger count to get the average position of all the fingers.

    When you say the tap.pos is registered as (Infinity, Infinity), does it happen in every tap event? Have you tried on any platform other than OSX? My guess is it's something to do with the system since reloading the build get rid of the issue, indicating the build itself is ok.
     
  12. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Hi, I am very interested in Input.Touches asset in combination with Playmaker!
    Is it possible to get the touch dimensions (w,h,r) with Input.Touches? I use win7 and a PQLabs Multitouch device and it offers these parameters....
    I need a solution for a interactive bar where user can place glasses, dishes on the multitouch device, also the user should be able to interact with his fingers... the dimesions of a touch (width, height, radius) input should trigger different states (for finger and object interaction depending on their dimension)!

    Thanks in advance,
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your interest. Unfortunately if I understand the (w, h, r) term correctly, I will have to dissapoint you here. See the library is built on Unity3D native touch input. The information given doesnt include the dimension info of the touch on screen. You can see the full list of the information available here: https://docs.unity3d.com/Documentation/ScriptReference/Touch.html
     
  14. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    346
    Thank you for your quick and precise answer!
    Had a look at the Unity3d library and you are right, these parameters are not part of this library... :(
    You have a really nice and well priced asset there, unfortunatly I need these parameters (at leatst r)!
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yea, sorry it's not much help to you. Good luck in finding what you need.
     
  16. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    762
    Hey songtan,

    I grabbed your Input.Touches plugin last night, good work. I do need some help!

    I'm currently using your plugin to setup my camera controls, I've got pinch to zoom in/ out working, however I'm having trouble getting the camera to move when the finger is dragged/ swiped (whichever is best?) across the screen.

    I want the camera to only move when it is zoom in (I've got a variable for this controlled by the pinching). Here's how I'm doing it for desktop, hopefully this shows what I'm trying to reproduce for touch screens - done before I purchased your plugin. How do I do this with your plugin?

    Code (csharp):
    1.         if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
    2.         {
    3.             if(zoomedOut == true)
    4.             {
    5.                 float wantMoveX = Input.GetAxis ("Horizontal") * moveSens * Time.deltaTime;
    6.                 float wantMoveZ = Input.GetAxis ("Vertical") * moveSens * Time.deltaTime;
    7.  
    8.                 Vector3 pos = transform.position;
    9.                 pos.x = Mathf.Clamp (pos.x + wantMoveX, minX, maxX);
    10.                 pos.z = Mathf.Clamp (pos.z + wantMoveZ, minZ, maxZ);
    11.  
    12.                 transform.position = pos;
    13.             }
    14.         }
    Thanks
     
  17. Song_Tan

    Song_Tan

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

    Since you are aftering continous movement, drag is the one you should be using. You can try something like this:

    Code (csharp):
    1.  
    2.     void OnDragging(DragInfo dragInfo){
    3.         if(zoomedOut){
    4.             //you may want to set the value of moveSens to something very small
    5.             Vector3 pos=transform.position+new Vector3(dragInfo.x, 0, dragInfo.z)*moveSens;
    6.             pos.x = Mathf.Clamp (pos.x, minX, maxX);
    7.             pos.z = Mathf.Clamp (pos.z, minZ, maxZ);
    8.             transform.position=pos;
    9.         }
    10.     }
    11.  
     
  18. Carwashh

    Carwashh

    Joined:
    Jul 28, 2012
    Posts:
    762
    Thanks for the help!

    I had to change it slightly, and it's not working properly yet (I had to go to bed). When you swipe, instead of moving around with the finger drag, it just jumps to the top right and becomes stuck (until zooming out)

    Code (csharp):
    1.     void OnDragging(DragInfo dragInfo){
    2.  
    3.         if(zoomedOut){
    4.  
    5.             //you may want to set the value of moveSens to something very small
    6.  
    7.             Vector3 pos=transform.position+new Vector3(dragInfo.pos.x, 0, dragInfo.pos.y)*moveSens;
    8.  
    9.             pos.x = Mathf.Clamp (pos.x, minX, maxX);
    10.  
    11.             pos.z = Mathf.Clamp (pos.z, minZ, maxZ);
    12.  
    13.             transform.position=pos;
    14.  
    15.         }
    16.  
    17.     }
    It says draginfo is passing a vector2, so had to use x and y, instead of x and z (I assume this is for the screen though, so makes sense) and .pos needed adding after the draginfo.

    Thanks for the help, much appreciated. I just need to work out why it jumps and isn't following the finger around now :)
     
  19. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    ops, sorry my bad. I typed that out in a hurry and didnt check for the error. I know what's causing the problem, try this:

    Code (csharp):
    1.         void OnDragging(DragInfo dragInfo){
    2.      
    3.             if(zoomedOut){
    4.      
    5.                 //you may want to set the value of moveSens to something very small
    6.                 //we are using position difference of the drag between each time frame, no the actual cursor pos
    7.                 Vector3 pos=transform.position+new Vector3(dragInfo.delta.x, 0, dragInfo.delta.y)*moveSens;
    8.      
    9.                 pos.x = Mathf.Clamp (pos.x, minX, maxX);
    10.      
    11.                 pos.z = Mathf.Clamp (pos.z, minZ, maxZ);
    12.      
    13.                 transform.position=pos;
    14.      
    15.             }
    16.      
    17.         }
     
    Last edited: May 8, 2014
  20. aero80

    aero80

    Joined:
    Jan 29, 2013
    Posts:
    27
    Hi there,

    Iam having a bit of problem with tap detection. I am using NGUI for ui stuff and Prime31's statekit. On main menu I register for tap events and upon tap game starts, game state changes to play state, and tap event is unregistered as expected. When game ends i show a ngui button to return back to home screen. When it is clicked state changes to home state but the game immediatly restarts. So basically tap is handled twice. Once for ngui and once for input.touches since states change instantly.
    Iam thinking disabling tap detection during play state since i dont need it or maybe at home state i could give some time before registering for tap events again.

    I was wondering if there is a better way of handling this kind of situation.

    Thanks.
     
  21. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You can add a small boolean flag to the tap detection script. When in home state ,set the flag to true. False if otherwise. Then you can check for the flag to determine if a game new should be started when a tap is detected. Of course, the flag is set to true by default. Upon a tap is detected it would be set to false. When the back to home screen ngui button is pressed, set the flag back to true. Safest and cleanest way I can think of. :)
     
  22. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Hello

    I imported Input.Touches and right off the bat I got these four errors:

    Assets/InputTouches/ExampleScripts/C#/DPad.cs(19,25): error CS0117: `Gesture' does not contain a definition for `onMouse1E'
    Assets/InputTouches/ExampleScripts/C#/DPad.cs(20,25): error CS0117: `Gesture' does not contain a definition for `onTouchE'
    Assets/InputTouches/ExampleScripts/C#/DPad.cs(24,25): error CS0117: `Gesture' does not contain a definition for `onMouse1E'
    Assets/InputTouches/ExampleScripts/C#/DPad.cs(25,25): error CS0117: `Gesture' does not contain a definition for `onTouchE'

    Then I removed Input.Touches and imported it again, and same errors.

    I have the latest version of Input.Touches available on the Asset Store and use a Mac with Unity 4.3.4


    Any help would be appreciated.

    Thanks
     
  23. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Have you try importing it into a fresh, empty project. My guess is you have other scripts in the project that is named Gesture, apart from the Gesture.cs used in InputTouches. Basically it's a naming conflict of some sort. Removing the other script would solve the problem. If you must use InputTouches and the other conflicting code, I'm afraid a name change will be needed.
     
  24. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    You're right

    I also have easyTouch which uses Gesture.cs. A developer who worked on my project installed it (and used it) but I don't have access to updates unlike Input.Touches which I bought in the UAS.

    Anyway, where else do I rename Gesture.cs in your plugin besides in the class?


    Thanks
     
  25. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Nevermind

    Unity prompted me of every instance of Gesture.cs and used MonoDevelop to change all.

    Not sure how many people have easyTouch and Input.Touches installed, but one of you guys should consider changing Gesture.cs to something else. In my case I used Gestures.cs.

    Don't listen to me, I am just a beginner who had trouble and went to sleep early because of this problem. :D

     
  26. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Doing a name change could be a quite messy process since it basically used in every script. I wouldnt recommend you to do it yourself unless you knows the package very well.

    Anyway, I have done a name changed version. If you just email me I can send the package to you.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that I will be on the move starting 26thMay until 13thJune so apologize in advance if I don't respond to any post in a timely manner.
     
  28. Binex-UmairBhatti

    Binex-UmairBhatti

    Joined:
    Nov 8, 2013
    Posts:
    8
    Hi,



    We are using input.touches for a runner game it works pretty well but there are some issues which are causing problems for us

    1. Fast Swipe are some time not detected (See image "1_SwipeNotDetected")
    2. There is big position difference of touch begin and end position reported by iOS and input.touches .(See Image "2_PositionDifference")
    3. While playing the game lots of the time the player finger moves in a curve rather then a straight line. this results in two swipes of different directions from input.touches.(See image "3_TwoSwipes")
    4. We did some debugging in the code and its appears there is small delay in capturing the touch begin position the cause of which seems to be yield return null in Ienumerator function "TouchSwipeRoutine" in swipeDetector Class. Due to this delay in capturing the start position the swipe detected by input.touches is too small to be consider a legal swipe. but in reality the player has made a legal swipe.


    To Highlight these issues we have plotted the position reported by iOS and input.touches on the screen. The red line represent the iOS while the blue line represent the swipe reported by input.touches.



    Waiting for reply,

    Umair Hameed Bhatti 1_SwipeNotDetected.PNG 2_PositionDifference.PNG 3_TwoSwipes.PNG
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm extremely sorry for the delay in responding. For some reason I've missed your post entirely and have only found out about it after casually checking my own thread.

    Now to address the issue. Can I start by asking the average frame rate of your app? The thing is InputTouches is very much frame rate dependent. If an app is running consistently at <15 frame per second, it can potentially breaks a lot of code since the sampling rate could be lower than what it's required to capture certain rapid input.

    1. I would try to decrease the MinSpeed and MinDistance value on SwipeDetector component. Chance are when the player do a quick swipe, either the swipe distance is too small to make it pass the threshold.
    2. Tbh I'm struggling to see where is this coming from. As far as I know I've only used value taken directly from the Unity Input class. If you dont mind, can I have a look at your code as to how you obtain the value used to drawn the line in the image. Also have you try to do a on screen debug to verify the touch position.
    3. I would increase the the MaxDirectionChange value on SwipeDetector component. The maximum allowed value is 90 and the swipe shouldn't unless the user swipe in a curve where the direction change is greater than 90 degree. If that's not the case, chance are it's other stuff that are breaking the swipe.
    4. I dont think the yield return null is a factor. See the start position and time is recorded before that line (so there's no delay). Then the code waits for a frame until it goes into a loop where the swipe detection is being run. We needed that delay for the readings to be updated and the user to move. All that in a 30fps app takes only 0.03 second, much faster than the user can tap the screen. So even with the smallest and fastest of swipe, the function would have loop 2-3 times. That is of course assume the app runs at 30fps, which is why I stated in advance the issue could be down the the frame rate.
     
  30. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Can you change Gesture class to InputTouchGesture. Gesture is a common name and it conflicts with other packages
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I agree. I've been getting loads of similar request. I'll get it to when I have time. If you are in a bit of hurry. I can send you an advance copy as soon as I can.
     
  32. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just a quick note that a new udpate (v1.1.5) has just gone live on AssetStore. There's nothing new in the update. The only thing I've done is change the class name Gesture to IT_Gesture to avoid naming conflict with other packages.
     
  33. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Hi, just purchased your plugin and it looks fantastic.
    I'm trying to detect simple swipe directions (left/right/up/down) in order to rotate something 90 degrees in that direction and am wondering if there's a built in method to evaluate this (which I can't find) or do I need to calculate the swipe angle returned and determine the overall direction of the swipe that way (eg: 315 to 45 degrees = up)? Thanks.
     
  34. SoftwareLogicAU

    SoftwareLogicAU

    Joined:
    Mar 30, 2014
    Posts:
    34
    Hi songtan,

    I'm happy to see I was on the right track!

    After looking through all these entries page by page I finally found someone who had asked the same question and your reply so all sorted.
    If anyone else stumbles on this question, the answer is:
    1. void OnEnable(){
    2. Gesture.onSwipeE += OnSwipe;
    3. }

    4. void OnDisable(){
    5. Gesture.onSwipeE -= OnSwipe;
    6. }

    7. //detect swipe direction
    8. void OnSwipe(SwipeInfo sw){
    9. if(sw.angle>=45 && sw.angle<135){
    10. Debug.Log("swipe up");
    11. }
    12. else if(sw.angle>=135 && sw.angle<225){
    13. Debug.Log("swipe left");
    14. }
    15. else if(sw.angle>=225 && sw.angle<315){
    16. Debug.Log("swipe down");
    17. }
    18. else{
    19. Debug.Log("swipe right");
    20. }
    21. }
     
  35. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase and sorry for the slow respond. Looks like you have beat me to the answer! :)
     
  36. Tommienu

    Tommienu

    Joined:
    Feb 19, 2014
    Posts:
    1
    Hi there,

    Thanks for a great plugin!

    One problem as of recently though, i keep getting this error:

    NullReferenceException: Object reference not set to an instance of an object
    IT_Gesture.MultiTap (.Tap tap) (at Assets/Plugins/InputTouches/Gesture.cs:242)
    TapDetector.CheckMultiTapMouse (Int32 index, Vector2 startPos, Vector2 lastPos) (at Assets/Plugins/InputTouches/TapDetector.cs:118)
    TapDetector+<MouseRoutine>c__IteratorB.MoveNext () (at Assets/Plugins/InputTouches/TapDetector.cs:468)

    Worked fine before an update, i believe my previous version of InputTouches was about 6 months old. Touches works fine though, but i still get the NPE in the console. Also, this is when using the mouse.

    Edit: Problem is still there when using Unity Remote and actually touching on the device.

    Any ideas? Thanks in advance.
     
    Last edited: Jun 19, 2014
  37. Binex-UmairBhatti

    Binex-UmairBhatti

    Joined:
    Nov 8, 2013
    Posts:
    8
    I have created a sample project in which input.touches is used. I have tested it on iPad3. FPS is not dropping on the device.
    • There are two scenes
    ◦ SwipeDemo
    ▪ Contain all the GUI elements
    ◦ SwipeDemoWithOutGUI
    ▪ GUI elements are disabled to improve FPS.
    • FPS is displayed in both scenes.
    • RunTimeInputDisplay.cs script displays the input.
    ◦ Red Line represents iOS input
    ◦ Green Line represents Unity input
    ◦ Blue Line represents Input.touches
    • In RunTimeInputDisplay
    • Input.touches inputs are received in SwipeReceived Function
    ◦ iOS inputs are received in IosStartPosRecived and IosEndPosRecived
    ◦ Unity inputs are received in Update function call.
    ◦ After receiving input UpdateInput function is called which displays input.

    • Drawing.cs class is used to draw lines on the screen.
    • iOS input is stored in RunTimeInputDisplay.cs which is taken from UnityView.m from XCode .
    • I have made video as well in which there are four swipes.
    ◦ In first three swipes, Input.touches line (blue line) is quite smaller then iOS (blue line )
    ◦ In the last swipe, Input.touches misses the input by saying swipe too short. But unity swipe (green line ) and iOS swipe ( red line) are detected.

    Video Link : https://www.dropbox.com/s/1vlniayyw119m68/InputIssueVideo.mov
     
    Last edited: Jun 25, 2014
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond guys. For some reason Unity forum has reset all my watched thread so I'm not getting any notification.

    @Tommienu, One thing I notice from the error log is that your Gesture.cs still kept its name. Since I've changed the class name you will need to rename the file name to match. It should be named IT_Gesture.cs. The other reason why the error could happen is that you dont have a IT_Gesture component in your scene. Unlikely I know, but just to make sure.

    @Binex-UmairBhatti, I'll take a look into it and get back to you. Thanks for your patient.


     
  39. e_tip

    e_tip

    Joined:
    Jan 27, 2014
    Posts:
    18
    hi songtan.
    i've bought your asset to handle multitouch events.
    i mainly need a two finger swipe up and down. i 've took a look to the api ref but i can see that two finger swipe is not supported. At the moment i've found a workaround using MFDraggingE but would be cool to know if this gesture will be natively supported somehow
    Thanks
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase. Unfortunately I have to say I won't be updating the package or add new gesture in the foreseeable future. So I'm afraid you will have to make do with MFDraggingE. Sorry to dissapoint.
     
  41. e_tip

    e_tip

    Joined:
    Jan 27, 2014
    Posts:
    18
    Ok, no problem. :)
    Last question. i have added two events onMFDraggingEndE and onPinchE .... but when i close the pinch to zoom MFDraggingEndE is called ... any hint ?
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Does that happen everytime you zoom? Were you doing a MFDrag before you start pinch?

    I cant figure out what is wrong. Looking at the code, I dont think that is possible. Both are operating under different condition and they are mutually exclusive.
     
  43. e_tip

    e_tip

    Joined:
    Jan 27, 2014
    Posts:
    18
    Uhm...
    Code (CSharp):
    1. void OnEnable(){
    2.         IT_Gesture.onMFDraggingEndE += HandleonMFDraggingE;
    3.         IT_Gesture.onDraggingE += HandleonDraggingE;
    4.         IT_Gesture.onPinchE += HandleonPinchE;
    5.         IT_Gesture.onDraggingEndE += HandleonDraggingEndE;
    6.     }
    7. voidHandleonPinchE (PinchInfoPI)
    8. {
    9.     pinch = true;
    10. dist += PI.magnitude * 0.01f;
    11. Camera.main.fieldOfView = dist;
    12. }
    13.  
    14. voidHandleonMFDraggingE (DragInfodragInf)
    15. {
    16. if (Mathf.Abs (dragInf.delta.x) > Mathf.Abs (dragInf.delta.y)) {
    17. return;
    18. }
    19. if (pinch)
    20. return;
    21. if (dragInf.delta.y > 0) {
    22. guiScript.nextAnimation();
    23. } else {
    24. guiScript.previousAnimation();
    25. }
    26. }
    27.  
    This is the code.. simply when i pinch to zoom and i get my finder closer... previuousAnimation is called
     
    Last edited: Jun 24, 2014
  44. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I guess that works. Just wondering how that happen in the first place. I'll have to do some testing to find out.
     
  45. xgeraldx

    xgeraldx

    Joined:
    Oct 31, 2012
    Posts:
    10
    I deployed the TapDemo to my Android device (Nexus 7) 4.4 and no touch events are registering...any ideas? Unity 3d 4.5
     
  46. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm not really sure what went wrong. Problem is I dont have the device to try things on my end. The way I see it, there are two possibility to this. Either some setting is wrong and InputTouches is not working as it should be, or touch input is not working at all on the device. Can you please let me know if any other gesture work? Try something simple like onTouchE.
     
  47. xgeraldx

    xgeraldx

    Joined:
    Oct 31, 2012
    Posts:
    10
    I tried a new project and added IT_Gestures.onTouchE += HandleTouch <-My touch event handler

    and still no joy. This is weird because it worked in another project I had prior to upgrading unity to 4.5 and upgrading Touches to the new version...
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I suspect the problem is the combination of Untiy4.5 your device. onTouchE is basically the Unity touch detection at it's most simplest form. If it doesnt work, that can only mean the native Unity touch detection is not working.

    You can try it out yourself with something like this:
    Code (csharp):
    1.  
    2. void Update(){
    3.     if(Input.touchCount>0){
    4.         for(int i=0; i<Input.touches.Length; i++){
    5.             if(Input.touches[i].phase==TouchPhase.Began) Debug.Log("touch down");
    6.         }
    7.     }
    8. }
    9.  
    And something just pops up on my mind, can you please check if you have IT_Gesture.cs instead of Gesture.cs. The script wouldn't work if it's name doesnt match with the class name.
     
  49. MoonifyPascal

    MoonifyPascal

    Joined:
    Aug 16, 2013
    Posts:
    12
    Hi Songtan,

    i'm using your plugin for quite a while now, and i'm facing an issue regarding multitap event.
    If i activate the TapDetector script, and if i declare the event in the OnEnable function.

    IT_Gesture.onMultiTapE += OnMultiTap;

    My iPad is simply crashing when i touch the screen, even once.



    OnMultiTap function is only doing a Debug.Log("Tap : "+tap.count);

    Thanks for your help
     
  50. xgeraldx

    xgeraldx

    Joined:
    Oct 31, 2012
    Posts:
    10
    Ok, I'm good now....I did a build for iOS and everything worked fine. So I restored my android device to a previous backup and everything works fine with it. Must have been the update I installed.... Thanks again for taking the time to help.