Search Unity

TouchScript — multi-touch library for Unity [RELEASED]

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

  1. matDru

    matDru

    Joined:
    Sep 19, 2013
    Posts:
    1
    Hi, i have similiar case as gabrielstuff, 2 cameras but looking in different directions and camera layers attached to them. It's very like in the "everything Combined" example but i cant seem to receive touch input from both of them simultanously -> when i switch their hierarchy in touchmanager instance always top one works. Is there any additional stuff that need to be set up while working with more than one layer? ( I also tried adding more layers to one camera but Unity wouldn't allow it ). To be precise: one camera is 2dcamera with full screen target script,simple scale gesture and small box in view; second one is 3d camera looking at model which has attached some pan gestures to it. When 2dCameraLayer is on top, i can zoom in/out ( the small box moves ) but can't move the model at all, with 3d on Top i can rotate model but the box stays in place no matter where i make scaling move. Hope you can point me to where the issue may be.

    Edit: Sorry, just found out the both cameras had background box collider which caused such behaviour. Second question is there a way to tell collider to listen to a particular gesture, but let other through it? Just looked at hit test example but it shows only ignore-all+discard or ignore-all-let-through scenario. Is listen-to-scale,ignore-and-let-through others scenario possible?
     
    Last edited: Sep 19, 2013
  2. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    I'm not sure what exactly you want but you can control how colliders work if you extend HitTest and put it to the object which has this collider.
    Check out the code for https://github.com/InteractiveLab/TouchScript/blob/master/TouchScript/Hit/Untouchable.cs
    Just add your logic and return a value from ObjectHitResult enum: https://github.com/InteractiveLab/TouchScript/blob/master/TouchScript/Hit/HitTest.cs
     
  3. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Hey guys,
    Glad to have found this instead of having to roll out my own for windows 8 but I have a question and I may have missed this on the fourm, but how would you instantiate a clone for the win7touchpoint?
     
  4. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    hm... I don't really get what you want to do.
     
  5. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Well I am trying to fire like bullets from the touch point, and just instantiate the clones like such:

    Code (csharp):
    1.  
    2.   Vector3 ray = new Vector3(touchDevice.transform.position.x,touchDevice.transform.position.y,touchDevice.transform.position.z);
    3.                          clone = Instantiate(projectile,ray, transform.rotation) as Rigidbody;
    4.                         clone.velocity = new Vector3(0,0, 50);
    5.  
    6.  
    The touchDevice is the touchdebugger that appears on the screen.
     
  6. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Err...
    It doesn't work this way.
    You need an object with collider and MetaGesture on it which dispatches events when touch points are changed.
     
  7. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Ohhhh, thanks for clearing that up, LOL. Good deal and great work on the project my friend. Is there a sample with this type of setup on it, I am new to this one and kind of confused at the moment.
     
    Last edited: Sep 21, 2013
  8. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Ok having a small issue, i have found metagestures and attached it to my camera and added my script to fire the ammo but nothing happens, so any advice would help here is what I have:

    Code (csharp):
    1.  
    2. // Use this for initialization
    3.     private void Start () {
    4.  
    5.    
    6.         var metaGesture = GetComponent<MetaGesture>();
    7.    
    8.         metaGesture.TouchPointBegan += OnTouchEvent;
    9.         metaGesture.TouchPointMoved += OnTouchEvent;
    10.         metaGesture.TouchPointEnded += OnTouchEnded;
    11.         metaGesture.TouchPointCancelled += OnTouchEnded;
    12.        
    13.        
    14.     }
    15.     void Update()
    16.     {
    17.         StartCoroutine(Firing());
    18.        
    19.        
    20.     }
    21.     IEnumerator Firing()
    22.     {
    23.      
    24.         while(true)
    25.         {
    26.            
    27.             if(doShoot)
    28.             {
    29.                 print("Help");
    30.                clone = Instantiate(projectile,ray, transform.rotation) as Rigidbody;
    31.                clone.velocity = new Vector3(0,0,5);
    32.            
    33.             }
    34.             yield return new WaitForSeconds(nextFire);
    35.         }
    36.     }
    37.     private void OnTouchEvent(object sender, MetaGestureEventArgs e)
    38.     {
    39.         doShoot = true;
    40.         //rocks.enabled = true;
    41.         ray = camera.ScreenToWorldPoint(new Vector3(e.TouchPoint.Position.x, e.TouchPoint.Position.y,camera.farClipPlane));
    42.                      
    43.         }
    44.  
    45.  
    Once again any help is appreciated.
     
  9. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    Has anyone else had the honor of getting an object to shoot from the touch point using metaGestures? For some reason my doesn't work.
     
  10. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    So I have my other issue fixed and my next question is not an issue just a question, are there any samples on how to handle swipe gestures with this package and how to do animations like showing a stretched slash animation?
     
  11. tmanallen

    tmanallen

    Joined:
    Nov 8, 2009
    Posts:
    395
    I have a question about metagestures. I have a metagesture attached to my camera and a touch debugger and when I touch the screen to instantiate a projectile it fires right from the center of the camera and not from the touch point of the touch debugger. Any suggestions on how to get it to fire from the touch point?
     
  12. francesco_ini

    francesco_ini

    Joined:
    Sep 17, 2012
    Posts:
    9
    Hi guys,

    i'm doing some experiments with TouchScript.

    I've look inside examples and search inside this thread but i can't find how to access the properties of a gesture...

    Example: I would like to rotate a cube with a Pan Gesture...how can i access the Delta or the Direction of the panning input ?

    Thanks a lot
     
  13. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Check out SImplePanGesture, what you are looking for are: LocalDeltaPosition, WorldDeltaPosition, LocalTransformCenter, WorldTransformCenter, WorldTransformPlane.
     
  14. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Hi guys...
    How did the NGUI integration ended up?

    I am picking a plugin for a windows 8 touchscreen project, and that is the only thing that remains as a question on my mind.

    Regards
     
  15. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    I didn't have time to research in this area since I personally don't use NGUI.
    But there was a guy who hacked his way into the lib with some success.

    But we can figure something out if you really need this stuff.
    Tell me more about your use case and what equipment you are using.
     
    Last edited: Oct 8, 2013
  16. Collonville

    Collonville

    Joined:
    Aug 8, 2013
    Posts:
    5
    Hi.I want to get coordinates each touched places.I`m using TUIO input and I have tried many way.Can anyone know how to do??
     
  17. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Valyard.

    Thank you very much for answering.

    I have started this project with TouchScript. As soon as I bump into something and I have a clearer idea of what limitations might be, I will get in touch.

    Best Regards
     
  18. kleinfb

    kleinfb

    Joined:
    Sep 21, 2012
    Posts:
    96
    Question...

    Is there a way for me to access the sender as another class other than plain "object"?

    If I had the GameObject it would aready be great. object class does not tell me much, and I have to work with it dealing with its name... (I have centralized inputs into a class to handle them, and it is kind of a pain to sort out where the gesture came from... I know there are other ways to handle it, but I would really like to get more info about the "sender"... that would be great for me.
     
  19. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    Hi guys and thank you! Question. When I use Fullscreen Target (Type: Foreground) gestures sometimes not recognized. How can I fix it?
     
  20. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    You generally should know which object sent an event. So you just do
    Or if you subscribed to many different gestures you can check their types
     
  21. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Fullscreen Target (Foreground) covers all the screen with a big collider so whatever is beneath it won't receive any touch events.
    If you got gestures on Fullscreen Target make sure that you add them to each other's WillRecognizeWith array so they can work together.
     
  22. francesco_ini

    francesco_ini

    Joined:
    Sep 17, 2012
    Posts:
    9
    Thanks !
     
  23. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hi there, I'm trying to get a swipe / click list to work. The structure is like this:

    - DragCube with a BoxCollider, PanGesture and my own "ScreenDragHandler" attached - this works flawlessly
    + UIGrid​
    o several objects instantiated during runtime from prefabs, with Collider, TapGesture and ScreenButtonHandler attached​

    So, when I originally set this up, it worked without a problem. I had "WillRecognizeWith" of the TapGestures assigned to the PanGesture.

    However, when I made it dynamic (the Buttons are now populated during runtime by instantiating prefabs), it stopped working. The buttons still work when I disable the "drag collider". When I have the "drag collider" active, sometimes the taps are recognized - but I'm getting very weird error messages (null reference exceptions where there cannot be null ;-) ).

    I do re-assign the "willrecognizewith" property of the TapGestures during runtime but that doesn't seem to solve it. Also, I tried manually setting everything up and it also didn't work.

    What am I missing here?
     
  24. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Hi. Sorry, this is (was) the ugly part. During runtime you should call gesture.ShouldRecognizeSimultaneouslyWith(anotherGesture, true).

    But this will be changed in the next release which is in develop branch right now. You should better get it now since WIllRecognizeWith property is gone. Instead there's a concept of friendly gestures. And in this way you should call gesture.AddFriendlyGesture(anotherGesture);
     
  25. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Ok, thanks, I'll give the develop branch a try ;-)
     
  26. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Awesome - that fixes all the issues I've had so far. Very nice!!! It was a bit of a pain to go from the DLL-based package to the "file-based" version from the develop branch (I probably could have compiled the DLL ... but ... I'm glad I didn't ;-) ).

    I noticed one issue you're probably already aware of: When you click on "Friendly gestures", it opens - but when you then try to drag another gestures in the field, it closes ... so that doesn't work. I worked around this by simply making those foldouts always be open.

    Me very happy ;-)
     
  27. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    I was talking about gestures from camera with Fullscreen Target. They are sometimes not recognized. for example panGestures.
     
    Last edited: Oct 18, 2013
  28. gfoxworthy

    gfoxworthy

    Joined:
    Nov 4, 2010
    Posts:
    24
    We are developing an application that will be installed on different platforms, with different input sources. As of now, we are controlling which input component is added at runtime through a config file, but it's an extra step that we'd like to avoid if possible.

    With that said, does TouchScript have any way to determine if an input source is available for use? For example, if I ran my app on a computer with a TUIO device, it would be ideal to then automatically add the TUIO input component and no others. If that check fails, it then looks for windows 7 native touch device and adds the appropriate input component, and finally falls back to mouse only if that condition fails. Any idea if this is possible?
     
  29. highlyinteractive

    highlyinteractive

    Joined:
    Sep 6, 2012
    Posts:
    116
    Hi there,

    I've got a problem with culling masks using Touchscript. I've put together a simple project to explain my problem.

    https://dl.dropboxusercontent.com/u/20093519/TouchTest.zip

    As you can see I've got two cameras with viewport rects, one rendering to the left half of the screen, the other to the right. There are two horizontal bars - touching them will set a random colour. If you touch the one on the right, it changes as expected. If you touch the one on the left, the right one still changes. Keep clicking further left you'll find the 'edge' of the right bar will be able to change the left colour. You can see in the editor window that the objects do not overlap.

    How can I get the touchscript hit areas to obey the camera rects? I've set up the camera layers layer mask properties, but that hasn't had the desired effect.

    My actual project is more complex I really need to make it work. Any idea how I can fix this?

    Thanks
     
  30. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Sorry, just noticed your post o_O
    Right now what you are saying you have to handle yourself.
    What's more, MouseInput and Windows touch inputs conflict since Windows sends mouse event with every first touch.
     
  31. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Yes, I stumbled upon this problem some time ago. There's even an issue at github for it.
    But I never had nor time nor necessity to fix it. I can't promise you when I can take a look at it but if you know c# you can take a look at actual code which does raycasting from a camera, it shouldn't be hard to figure it out. The code is in this file: https://github.com/InteractiveLab/TouchScript/blob/master/TouchScript/Layers/CameraLayer.cs
     
  32. highlyinteractive

    highlyinteractive

    Joined:
    Sep 6, 2012
    Posts:
    116
    Thanks for the speedy reply.

    I have to say, I wouldn't know where to begin with a fix - I don't have any experience with raycasting sadly.

    Am I right in thinking that the problem is that CameraLayer doesn't factor in the viewport rect of the camera?
     
  33. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    You are right, it doesn't.
     
  34. CraigGraff

    CraigGraff

    Joined:
    May 7, 2013
    Posts:
    44
    Looking at the source code project I notice a Lib folder that wants me to add Unity dlls. Could you please tell me which dlls are required and/or where they might be found?

    Edit: Never mind - I eventually figured out that it was the UnityEngine.dll that I needed.
     
    Last edited: Nov 12, 2013
  35. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Yes, UnityEngine and UnityEditor.
    $download (2).png
     
  36. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Does it Works on Windows Phone? How to attach the plugin to the game?
     
  37. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    On Windows Phone you should use MobileInput instead of other inputs.
    You should delete all other DLLs except TouchScript.dll.
     
  38. GustavoH

    GustavoH

    Joined:
    Sep 29, 2013
    Posts:
    116
    Yes... Then what code page i've to attach to the object i want to move?
     
  39. J566

    J566

    Joined:
    Nov 15, 2013
    Posts:
    2
    I'm running into a problem where I have four different TUIO streams (different computers) feeding the unity machine - TouchScript thinks I'm no longer touching because each stream only contains touch data for a specific screen. The behavior while pressing my finger to the screen and not releasing is a bunch of up/down touches over and over again making the unity app unusable. Is there a way to make TouchScript wait 'X' number of not being read before it counts as not touching?
     
    Last edited: Nov 15, 2013
  40. cursed1cursed1

    cursed1cursed1

    Joined:
    Jun 30, 2013
    Posts:
    18
    hello i want use flick gesture but only rotate how to move cube with flick

    i need little move examples :(
    sorry my english


    Thank you for this script
     
    Last edited: Nov 18, 2013
  41. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Have you seen the flick example which is included in the package?
     
  42. cursed1cursed1

    cursed1cursed1

    Joined:
    Jun 30, 2013
    Posts:
    18
    only rotator
    flick the cube and cube rotate very nice examples
    but how to move i dont know and no examples flick move need help :(
    thanks for reply
     
  43. Asta_D

    Asta_D

    Joined:
    Oct 16, 2013
    Posts:
    15
    Hi
    I am new to Touchscript, but it is realy cool. I figured out, how to aplly taps and other gestures. But i don't get it how to rotate an object by using SimplePanGueste (As you mentioned above)? Is there a tutorial somewhere, how to do so?
     
  44. cursed1cursed1

    cursed1cursed1

    Joined:
    Jun 30, 2013
    Posts:
    18
    someone help me
    flick move impossible this Touchscript?
     
  45. Asta_D

    Asta_D

    Joined:
    Oct 16, 2013
    Posts:
    15
    Ok, i got it. I did it like this
    Code (csharp):
    1.  
    2. private void onPanStateChanged(object sender, GestureStateChangeEventArgs e){
    3.              switch (e.State)
    4.             {
    5.                 case Gesture.GestureState.Began:
    6.                 case Gesture.GestureState.Changed:
    7.                     var gesture = (SimplePanGesture)sender;
    8.                     if (gesture.LocalDeltaPosition != Vector3.zero)
    9.                     {
    10.                        float h = horizontalSpeed* -1 * gesture.LocalDeltaPosition.x *5;
    11.                        transform.Rotate(0, h, 0);
    12.                      }
    13.                  break;
    14.             }
    15.         }
    16.  
    Now i try to figure out, how to make an ease out. So if you finish the gesture that it dosn't stop directly. The rotation should slow down and come to a soft stop after a second. Do you have any hints?
     
  46. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    just save h to a class variable and in Update do something like
    Code (csharp):
    1. transform.Rotate(0, (transform.eulerAngles.y + h)/3, 0);
     
  47. Asta_D

    Asta_D

    Joined:
    Oct 16, 2013
    Posts:
    15
    Hi valyard
    Thanks for the hint. But if i put that in update, my object is spinning around like crazy. And that while dong the gesture and after finishing the guesture.
     
  48. SpaceMammoth

    SpaceMammoth

    Joined:
    Jan 2, 2013
    Posts:
    220
    Hi, this is a very nice package, however I'm having some issues with it in Unity Basic 4.3 (game is targetting PC Standalone) on Windows 8.1 on the Surface Pro 2.

    Just using the basic demo scene that makes the cubes appear when tapped, it partially works. When I tap, about 50% of the taps are making a cube, but many seem not to register at all. If I do a similar style tapping in MS Paint, all taps register. I don't know if sometimes I am hitting for slightly too long and the PC is assuming I am doing a right-click style hold?

    Has anyone else had similar issues/am I doing something stupid?

    Anyone else using the surface pro with TouchScript?
     
    Last edited: Nov 25, 2013
  49. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Hi.

    2d support is in beta mode in develop branch.
    Please clone it and test if everything works fine.
    There's new CameraLayer2D which detects touch points over Collider2D objects.
     
  50. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    I actually tested the examples on a Windows 8.1 tablet not long time ago.
    I didn't notice touch points missing but indeed some of them might be interpreted as right click by the system.
    As I don't have a windows 8 touch enabled PC at the moment I can't test it and find out how to get rid of it )8