Search Unity

TouchScript — multi-touch library for Unity [RELEASED]

Discussion in 'Assets and Asset Store' started by valyard, Mar 6, 2013.

  1. Carsten-Germer

    Carsten-Germer

    Joined:
    Nov 20, 2013
    Posts:
    7
    Hi valyard,
    first, congratulations for this great framework!
    I've been playing around with the examples and I love it.

    - I'm prototyping with Unity 4.3.0f4 free but will step up to pro later
    - Project will be on iOS, Android, WindowsPhone
    - I can't have the users install TUIO on the devices

    Before I go full force with my project I would like to ask a few (hopefully) simple questions, if and how that is possible with the described limitations:

    1. I need Tap, DblTap, Flick and Swipe.
    My guess from the documentation is that the "Swipe" would be a PanGesture, am I correct?
    How would I go about DblTap?

    2. Flick and Swipe should interact with specific gameObjects if the starting _or_ ending TouchPoint is on this gameObject. I can't seem to find how to do this.
    Would I attach the Flick and Swipe gestures to the gameObject?
    If, would this register when the gesture both starts _and_ ends with TouchPoint on the gameObject?
    Or, better go with FullscreenTarget on the camera and check the Touchpoints (the gameObject moves...)?

    Any advice is highly appreciated, I hope to be able to contribute a nice prototype-game-example to this great project.

    Cheers /Carsten
     
  2. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Thanks.

    For free version you need to delete TouchScript.Pro.dll since there are references to classes not supported in free version.

    Tap is implemented. Double tap is not. And if you want to combine tap and double tap on one object it will be tricky. I planed to implement this functionality but I personally have never needed it. Swipe might be like a PanGesture but you will probably need to code your script to add inertia to this movement.

    By default touch points are grabbed by gestures which are on objects these touch points hit. Hover or enter effect is a bit tricky to implement.
    By default you can't have a gesture detect if a touch point ended on a specific object. You will have to cast rays in the scene manually.

    I think I can reserve some time to resolve single tap/double tap on one object if you need this.
    As for the others, right now I don't know what a Swipe gesture should be and how to integrate movement inertia properly.
     
  3. Carsten-Germer

    Carsten-Germer

    Joined:
    Nov 20, 2013
    Posts:
    7
    Hey valyard, thanks for the quick reply!

    No need for Tap and DblTap on one object. I just need a DblTap gesture on certain objects.

    I experimented some more today, what I ment with "Swipe" is more like a slow(er) Flick in TouchScript (googling "swipe gesture" will find explanatory pictures).
    Flick with modified parameters will do nicely for my purposes.

    An example to check if I got this right:
    I have a small Object moving over the screen. FlickGesture is a component of that Object.
    With this, the starting TP as well as the ending TP would have to be on that object for the gesture to be recognized?

    If I got this right, then I would have to tie FlickGesture to the camera, like in TouchScript/Examples/Flick.
    How Do I relate starting or ending TP to my object? Cast rays, right?
    Now, how Do I get starting and ending TP? With FlickGesture.touchesBegan and . touchesEnded, retrieving the respective TouchPoint and reading it's .Position?

    You see, I'm swimming a bit here, trying to wrap my head around the way to get marching ;)
     
  4. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    It should be easy to convert TapGesture into a DoubleTapGesture, I'll take a look tomorrow.

    No, when gesture starts it owns touch points which started it. So you can move your hand wherever you want. But when you lift off all the fingers some gestures check if you are actually still over the object. FlickGesture doesn't. TapGesture does if configured so.[/QUOTE]
     
  5. teemu-parkkinen

    teemu-parkkinen

    Joined:
    Mar 28, 2013
    Posts:
    2
    In my project after Application.LoadLevel(0); (restart the scene) .StateChanged doesn't work anymore. Any help for that?
     
  6. teemu-parkkinen

    teemu-parkkinen

    Joined:
    Mar 28, 2013
    Posts:
    2
    I just find the solution. I've to add the gesturemanager manually in Start function this.gameObject.AddComponent("GestureManager");
     
  7. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
  8. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Try the latest develop branch. I've been working on this.
     
  9. Carsten-Germer

    Carsten-Germer

    Joined:
    Nov 20, 2013
    Posts:
    7
    That would be a great help, thanks.
    If it fits, I can volunteer for creating DblTap sometime within the first quarter of 2014, when production for this game will go into gears.
    I guess I need to wrap my head around creating my own gestures, anyway. But if it's sufficiently easy for you, I would also love to learn about creating additional gestures studying your example for DblTap ;)

    Perfect for my use case! Thanks for clearing that up, shows that I didn't dive deep enough into the sources yet.

    We're releasing a different project before xmas and another one targets Q1/2014. By that time, or shortly after that, my prototype should be presentable.
     
  10. kiril-cvetkov

    kiril-cvetkov

    Joined:
    Oct 18, 2013
    Posts:
    3
    Hello, How can I retrieve the x/y coordinates when I "tap" somewhere?
    I'm trying to make a swipe gesture (left to right) and (right to left)...
     
  11. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    You can do it using Gesture.ScreenPosition.
     
  12. kiril-cvetkov

    kiril-cvetkov

    Joined:
    Oct 18, 2013
    Posts:
    3
    Thanks a lot.. I started with reading the documentation right now, And hope that will make that gesture.. Touchscript rocks :)

    Anyway,In order to make it: Can I use simple check in "onRelease(object, GestureStateChangeEventArgs)"method ?
    if x'<x then the gesture is from left to right, otherwise from right to left

    private void onRelease(object sender, GestureStateChangeEventArgs e)
    {
    //Simple if condition..
    }

    private void onPress(object sender, GestureStateChangeEventArgs e)
    {

    }
     
  13. kiril-cvetkov

    kiril-cvetkov

    Joined:
    Oct 18, 2013
    Posts:
    3
    Ok.. Here's what I've done..

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using TouchScript.Gestures;
    5. using TouchScript.Events;
    6.  
    7.  
    8.  
    9. public class SwipeGesture : MonoBehaviour {
    10.  
    11.     // Use this for initialization
    12.     private PanGesture gesture;
    13.     void Start () {
    14.     gesture = GetComponent<PanGesture>();
    15.     if (gesture != null)gesture.StateChanged += onPan;
    16.     if (gesture != null) gesture .StateChanged += onRelease;
    17.    
    18.     }
    19.    
    20.     // Update is called once per frame
    21. private void onRelease(object sender, GestureStateChangeEventArgs e)
    22. {
    23. Gesture k = (Gesutre) sender;
    24.        
    25.     if (e.State == Gesture.GestureState.Recognized)
    26.               Debug.Log("Release"+k.x+"  "+k.y);
    27. }
    28.  
    29. private void onPan(object sender, GestureStateChangeEventArgs e)
    30. {
    31. ///I Tried with referencing gesture var... but without success
    32.     if (e.State == Gesture.GestureState.Recognized)
    33.         Debug.Log("Pan"+gesture.ScreenPosition.x+"  "+gesture.ScreenPosition.y);
    34.        
    35. }
    36.    
    37. }
    38.  
    But I get null value of x/y ... Any suggestions ?

    Output : Pan Nan
    Release Nan
     
    Last edited: Nov 30, 2013
  14. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    As PanGesture is continuous you need to check for Gesture.GestureState.Began and Gesture.GestureState.Changed.
    Gesture.GestureState.Recognized is when the gesture ends.
     
  15. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    ok, I have what seems to be a classical problem :/

    I have an object which I rotate with PanGesture... and I have a FullScreen target, which is where I get info for a "ScaleGesture"... basically, zoom in and out...
    Problem is that the foreground collider covers the device one... and I need to have the device answering to PanGesture...

    I tried, but I cannot add more than one CameraLayer to a single cam...

    Can anyone please suggest me something? I do not think it is good practice to have an extra cam on this scene, when I surely do not need one...
     
  16. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Originally I wanted a layer to be like "a layer which you can see" so several layers on a camera didn't make sense.
    What you are trying to do is not really a good practice. What is going to be fullscreen and touchable should really be in the back. Physically.

    But now I think that you probably can have several layers on a camera.
    In the latest develop build I removed this constraints.
    You can have two layers on a camera checking for different visibility layers. And sort them on TouchManager.
     
  17. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Hey Valyard, thanks for the answer.

    I have to say I really don't see my objective as bad practice... I want a scale gesture to be recognised anywhere on the screen... and I have a small object which has to be able to receive a pan gesture... if I have the scale collider on the back, scale gesture over the small pan object will not be received... if I have it on the scale collider on foreground, I will not be able to have the pan gesture recognised on the small object. How could this be bad practice.. I mean... it is something I am trying to achieve, it is not even a practice o_O and the background collider will get covered by this small object, so if I scale gesture over it, the background collider does not get the input.

    Still, I have "solved" it by adding a scale gesture for the small object on the front too.. problem is that I either have to touch 2 fingers on the object, or 2 fingers on the background... 1 finger over the object and one finger over the back will not work...

    Main question, now:
    Where can I get the touchscript version with removed constraints for adding camera more than one camera layer to a cam?

    Thanks again, valyard, you are a very important person in this world! :D
     
  18. JParies

    JParies

    Joined:
    Dec 4, 2013
    Posts:
    14
    Anyone having luck using this library on Windows 8/Surface? I am trying to incorporate it into a project running on a Surface, but the touch points are way off to the right and down from where I'm touching the screen. I assume this is due to the scaling Win8 is using, but not sure how to work around it so the library accurately positions the touch on the screen.

    TIA
     
  19. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    I have to say windows 8 touch screen is working 100% for me.
     
  20. JParies

    JParies

    Joined:
    Dec 4, 2013
    Posts:
    14
    Are you on a Surface? The native resolution of the screen is 1920x1080, but under Settings/Change Settings/PC and devices/Display, there is a "More Options" drop down that scales UI elements for higher resolution displays. "Default" is a huge miss, while "Smaller" works as expected.

    Unfortunately, "Default" is the default, and I can't expect people to change their PC Settings to use an app I built.
     
  21. JParies

    JParies

    Joined:
    Dec 4, 2013
    Posts:
    14
    Following up - not sure what is causing the problem, but I no longer think is a resolution issue as I've been able to "corrupt" the Hit Test scene by copying my camera into it. At least, I *think* that's what did it.

    The behavior is strange. I touch the screen and drag my finger. Several seconds later, the touch target shows up below and to the right of where I touched, then traces the movement I made with my finger in its offset position.
     
  22. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Do you have another display connected to your surface or something?
     
  23. JParies

    JParies

    Joined:
    Dec 4, 2013
    Posts:
    14
    No - this is directly on the machine, and I've been able to repeat it on another system with a project that was working, and then began exhibiting this behavior. Still trying to figure out exactly what causes it, but the cause isn't jumping out at me just yet.
     
  24. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Valyard, I have to repeat myself, because it is an important question :/

    Main question, now:
    Where can I get the touchscript version with removed constraints for adding more than one camera layer to a cam?
     
  25. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
  26. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Oddly enough, I am working with someone who is relating a lot of issues on windows surface. I have a perfect behaviour on my asus pc windows 8 touch.

    Apparentely, the scalegesture which I use to zoom in/out is all "jumpy".. and sometimes, no gesture is recognized at all.

    Do you know anything about that, Valyard?

    Again, I cannot thank you enough
     
    Last edited: Dec 5, 2013
  27. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Unfortunately I don't have a windows 8 touch device so I'm not able to reproduce this issue or debug it.
    Someone experienced enough with a windows 8 tablet should try to debug it.
     
  28. badescuga9

    badescuga9

    Joined:
    Dec 11, 2012
    Posts:
    37
    I have a problem: i have a Touch Manager script, A mobile script and a Mouse script attached to an object in scene A. Also attached are a SimplePanGesture and other such gesture manipulators that work together,

    The touch methods work great, but when i go to another scene (thus deleting this scene) and go back to a new scene A with the same touch script attached, the touch gestures are not recieved. What am i doing wrong?

    Note: the problem is pressent on the device (ipad mini) and in the editor (OS X), i have the latest asset store version of TouchScript and Unity 4.3.0
     
    Last edited: Dec 10, 2013
  29. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Can you try the latest version in develop branch?
    Earlier I addressed this issue.

    https://github.com/InteractiveLab/TouchScript/tree/develop
     
  30. badescuga9

    badescuga9

    Joined:
    Dec 11, 2012
    Posts:
    37
    Thanks valyard, worked like a charm! Keep up the great work!

    BTW i picked up a strange bug on the ipad mini with ios 6.0.1 on it. If I changed the anti-aliasing in the OnRelease Method to QualitySettings.antiAliasing = 0 (it was 2) the OnPress and after that OnRelease would execute in this order (they are related to PressGesture and ReleaseGesture). I Am using this to load some stuff in the scene. The 2 events are set to work together.

    The bug doesn't appear on OSX, It's very strange.. i don't know if it's more from TouchScript or from Unity itself. If i comment the anti-aliasing code, the problem disappears. The problem appeared also on older versions of TouchScript (pre-3 version + Unity 4.2.1).
     
    Last edited: Dec 11, 2013
  31. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Sorry, not enough info.
    Can you post an issue on Github?
     
  32. valerik

    valerik

    Joined:
    Aug 8, 2013
    Posts:
    11
    Reply to old post that need to get coord of the surface hitted by the raycast:

    I added this method in my TouchManager.cs:
    Code (csharp):
    1.  
    2. public RaycastHit getRaycastHit(Vector2 position){
    3.     RaycastHit hit;
    4.     TouchLayer layer;
    5.     if (GetHitTarget(position, out hit, out layer)){
    6.         return hit;
    7.     }else{
    8.         hit = new RaycastHit();
    9.         return hit;
    10.     }
    11. }
    pay attention to the fact that I can't return an hit = null, so i place an empty RaycastHit (hit.point is a Vector3 (0,0,0))

    how to call?

    Code (csharp):
    1.  
    2. Debug.Log(this.touchManager.GetHitTarget(this.tg.ScreenPosition));
    3. if(this.touchManager.getRaycastHit(this.tg.ScreenPosition).point != Vector3.zero){
    4.     Debug.Log(this.touchManager.getRaycastHit(this.tg.ScreenPosition).point);
    5. }
    where tg is my TapGesture attached to the GameObject
    and touchManager is the reference to the script TouchManager.cs that you use to have touchscript in your scene.
    ;)
     
  33. OP3NGL

    OP3NGL

    Joined:
    Dec 10, 2013
    Posts:
    267
    hi, i downloaded from github as a unitypackage.... how do i make this work? there's no documentations whatsoever

    with mouseinput no problem....

    unity3D 4.3
    win7 pro 64bit
    Dell P2314T multi-touch monitor
     
    Last edited: Dec 18, 2013
  34. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
  35. Jirkarrr

    Jirkarrr

    Joined:
    May 22, 2013
    Posts:
    5
    Hey guys!

    First thanks for this tool, its amazing!

    Second I got stacked and I cannot solve this problem:

    I have implemented FullScreenTarget and ScaleGesture and registered void scaleHandler(object sender, GestureStateChangeEventArgs e)

    The problem is that when the ScaleGesture is recognized I do not know if the scale was down or up.

    After the gesture is recognized I want to scale my player accordingly, do you know how can I get that info?

    Thanks for any help.
     
  36. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Simple, delta scale = 1 — no scale, delta scale < 1 — scale down, delta scale > 1 — scale up.
    You don't add scale you multiply it.
     
  37. Jirkarrr

    Jirkarrr

    Joined:
    May 22, 2013
    Posts:
    5
    Thanks for your reply, I tried that one. The problem is that Delta scale is all the time equal 1

    I guess it is because the object did not scale yet.


    BTW: I am using Flick example
    FullScreenTarget and ScaleGesture are on Camera.

    private void Start()
    {
    GetComponent<ScaleGesture>().StateChanged += scaleHandler;
    }


    private void scaleHandler(object sender, GestureStateChangeEventArgs e)
    {
    if (e.State == Gesture.GestureState.Recognized)
    {
    float deltascale = (sender as ScaleGesture).LocalDeltaScale;

    Debug.Log("scale");
    Debug.Log(deltascale); // 1!!!!!!!

    }
    }

    EDIT2: I understand that when I touch and scale the object with ScaleGesture on it, it will immediately scale. Is there a solution for a situation when I am touching and scaling the Background/FullScreenTarget (not the object I want to scale) it will scale same way?
     
    Last edited: Dec 18, 2013
  38. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    You need to use if (e.State == Gesture.GestureState.Began || e.State == Gesture.GestureState.Changed). Since it's continuos gesture. GestureState.Recognized fires when gesture stops.
     
  39. Jirkarrr

    Jirkarrr

    Joined:
    May 22, 2013
    Posts:
    5
    YOU MADE MY DAY!! thanks a lot!!!
     
  40. OP3NGL

    OP3NGL

    Joined:
    Dec 10, 2013
    Posts:
    267
    does the package work in editor or i must compile to an exe file for it to work?

    another thing, what's the TUIO input port for?
     
  41. valerik

    valerik

    Joined:
    Aug 8, 2013
    Posts:
    11
    Hi again!

    Reading the documentation
    so by this, I can't automatically recognize a double tap because they are two different event with two different cluster, right?

    I ask you this before start to think a way to recognize two single tap as a single double tap ( i'm thinking on saving Time.time 1 and Time.time 2, if ( 1-2 > something -> double tap, else, single tap, or use hit coord, or both)

    Thanks in advance!
     
  42. Heaven Brook

    Heaven Brook

    Joined:
    Jul 26, 2013
    Posts:
    4
    Hi, I added Win 7Touch Input to an empty game object in the scene, build win64 exe, run on HP TouchSmart with win7, but multi touch not working, only single touch works.
    If I disable Mouse Input in the empty game object, only enable win7 touch input, both single touch and multi touch not working.
    Multi touch is working well with Paint and Google Map.
    HP Touch Smart only support 2 touches, does that matter?
    My Unity is trial pro latest version on Mac.
    $Screen Shot 2013-12-20 at 12.17.05 PM.png
    Please help, Thanks in advance.
     
  43. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Windows touch doesn't work in the editor.
    TUIO input port is to open a UDP socket and listen to incoming TUIO messages.
     
  44. Heaven Brook

    Heaven Brook

    Joined:
    Jul 26, 2013
    Posts:
    4
    I am wondering HP TouchSmart All-in-one is not a REAL Touch screen, which only supports 2 touches. It just simulate touches to mouse input. When I disable Mouse Input, the touch does not work at all. I also can use ALT+Mouse or ALT+Touch to simulate multi touches.
    Who can clarify me? I don't have other touch screen like Dell S2340T multitouch monitor to approve my thoughts.
     
  45. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Right, double tap needs a separate gesture. Like a tap which waits for another tap in not more than a second.
    The real problem is doubletap + single tap on one object. This won't work.

    I still have plans to implement double tap, just don't have time atm.
     
  46. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Right click on "My Computer" -> Properties. Does it say there multitouch with 2 touch points?
    Try if they work in Paint. Try to build a 32bit app.
     
  47. valerik

    valerik

    Joined:
    Aug 8, 2013
    Posts:
    11
    if someone need to recognize two tap as a double tap, this can be usefull.


    Code (csharp):
    1.  
    2. public float firstTouch;
    3.     public float secondTouch;
    4.     public bool firstLastTouch;
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8. //      Used by TouchScript
    9.         GetComponent<TapGesture>().StateChanged += HandleStateChanged;
    10.  
    11.         this.firstTouch = -1f;
    12.         this.secondTouch = 0f;
    13.         this.firstLastTouch = true;
    14.     }
    15.  
    16.     private void HandleStateChanged(object sender, TouchScript.Events.GestureStateChangeEventArgs e){
    17.         if (e.State == Gesture.GestureState.Recognized){
    18.             TapGesture gesture = sender as TapGesture;
    19.  
    20.             if(firstLastTouch){
    21.                 this.secondTouch = Time.time;
    22.                 this.firstLastTouch = false;
    23.                 if(this.secondTouch - this.firstTouch <0.2f){
    24.                     //.....
    25.                 }
    26.             }else{
    27.                 this.firstTouch = Time.time;
    28.                 this.firstLastTouch = true;
    29.                 if(this.firstTouch - this.secondTouch <0.2f){
    30.                     //.....
    31.                 }
    32.             }
    33.         }
    34.     }
     
  48. Heaven Brook

    Heaven Brook

    Joined:
    Jul 26, 2013
    Posts:
    4
    Thanks, valyard,
    32 bit app is kind of working, but the first touch is treated as 2 touches on same spot, so if you put 2 fingers on screen, there are 3 touches totally, two of them are same position, this causes the gesture function not working properly.
    My computer properties says Pen and Touch: Touch Input Available with 2 Touch Points.
    Paint is working with one or two touches only, three or more not working.

    I am thinking this dual touch monitor is different from multi-touch one, the code has to be different.

    Anyway it is a progress, I can adjust my code, it is weird 64bit app is not working on 64bit system.

    Great job, valyard.
     
  49. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    I'll take a look in 64bit app. There was a fork fixing some 64bit errors.

    As for 2 touch points at one touch this is probably because you have windows touch and mouse touch turned on simultaneously.
     
  50. Heaven Brook

    Heaven Brook

    Joined:
    Jul 26, 2013
    Posts:
    4
    After disable Mouse Input, it works great on win 32bits dual touch monitor! Thank you very much, valyard.