Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] FingerGestures - Robust input gestures at your fingertips!

Discussion in 'Assets and Asset Store' started by Bugfoot, Jul 8, 2011.

  1. Antidote

    Antidote

    Joined:
    Dec 28, 2009
    Posts:
    36
    Hi Spk,

    I followed the video that you posted on Youtube and tried to access Finger Gestures from a javascript.
    1 - I placed Finger Gesture Initializer prefab in the scene,
    2 - I placed an empty in the scene and drag a Long Press Gesture Recognizer.
    3 - I used the javascript skeleton to write the following script.
    What I want to achieve is switch On the graphics on Long Press and switch the camera position on Tap.
    Is that possible to add another action / Finger gesture type on a same object ?
    The object is an empty with a box collider.

    Version : FingerGestures v2.2 (November 15th 2011)
    Here is the error message that I got :
    Assets/Scripts/Select_Ball.js(54,38): BCW0005: WARNING: Unsubscribing from event 'FingerGestures.OnFingerLongPress' with an adapted method reference. Either change the signature of the method to 'callable(int, UnityEngine.Vector2) as void' or use a cached reference of the correct type.

    King regards,

    -------------------------------------------------------------------------------------------------------------------

    // variables
    var cibleBall: GameObject;
    static var posCamBall : Transform;
    static var posTargetCamBall : Transform;
    var targetCam : Transform;
    var sonIn : AudioClip;
    var sonOut : AudioClip;
    var graph : boolean;
    var tailleDistance : GameObject;
    var rotationAmount : float = -40;
    var rotCos : float = 0;
    var ballGaphAmplitude : float = 0;


    function Start(){
    ballGraphAmplitude = 0;
    tailleDistance.renderer.enabled = false;
    tailleDistance.transform.localScale = Vector3(0, 0, 0);
    graph = false;
    }

    function OnEnable()
    {
    // Register to FingerGestures events
    FingerGestures.OnFingerLongPress += FingerGestures_OnFingerLongPress;
    }


    function FingerGestures_OnFingerLongPress( fingerIndex : int, fingerPos : Vector2 )
    {
    if(graph == false)
    {
    audio.PlayOneShot(sonIn);
    iTween.ScaleTo(tailleDistance, {"x":15,"y":15,"z":15,"time":0.6,"transition":"easeInCubic"});
    graph = true;
    }
    else
    {
    audio.PlayOneShot(sonOut);
    iTween.ScaleTo(tailleDistance, {"x":0,"y":0,"z":0,"time":0.6,"transition":"easeInCubic"});
    yield WaitForSeconds(0.35);
    tailleDistance.renderer.enabled = false;
    graph = false;
    }
    }


    function OnDisable()
    {
    // Unregister FingerGestures events so we will no longer receive notifications after this object is disabled
    FingerGestures.OnFingerLongPress -= FingerGestures_OnFingerLongPress;
    }

    function Update () {
    var x = cibleBall.transform.position.x;
    var y = cibleBall.transform.position.y;
    var z = cibleBall.transform.position.z;
    transform.position=Vector3(x,y,z);
    transform.LookAt(targetCam);
    rotCos += 0.1;
    tailleDistance.transform.localScale = Vector3(ballGraphAmplitude, 0, ballGraphAmplitude);
    tailleDistance.transform.Rotate(Vector3(0, rotationAmount*Time.deltaTime, 0));
    tailleDistance.transform.position.y = 0.1;

    if (graph == false) {
    ballGraphAmplitude = 0;
    }
    if(graph == true) {
    ballGraphAmplitude = 15 + 0.15* Mathf.Cos(rotCos);
    }

    }

    // Another function to switch the camera position that I need to change because it will switch the camera each time I longpress on the collider
    function OnMouseUp ()
    {
    CamSelection.changePosRun = true;
    CamSelection.camActiveBall = true;
    }


    @script RequireComponent(AudioSource)
     
  2. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    Lol...how I missed this forum thread is beyond me. I am pasting what I started on another thread.

    I am using "FingerGestures" plugin and while using it on the pc, everything has worked perfectly. Now recently I have brought it over to my ipod touch and I am having problems with picking up a double tap wiht the code below. Is there something I am doing wrong? I tried using what they had in the tutorial.

    The Debug.Log displays 1 tapCount most of the time. It seems if I double-tap on the screen in the exact location with light taps, that it registers a tap count of two, but I have a gun I am firing and I just want the gun to fire no matter where they double tap. Is this possible? I don't have a button for reference on the screen so I just wanted the gun to fire when the user performs a double tap on the screen, even if it the finger is not coming down in the same location.

    Code (csharp):
    1.  
    2. void FingerGestures_OnFingerTap( int fingerIndex, Vector2 fingerPos, int tapCount )
    3. {
    4.     Debug.Log("Tapcount:" + tapCount);
    5.        
    6.     //Enter into FireGun
    7.     if( tapCount >= fireTapCount )
    8.     {
    9.         Managers.Gun.Fire();
    10.     }
    11. }
    12.  
     
  3. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Here's one way to do what you're after:
    1) Create/use a custom tap gesture recognizer
    2) Set its "Required Taps" property to 2 so that it only triggers on double taps (make sure the "Raise Event On Each Tap" is disabled)
    3) set its "Move Tolerance" property to something really big, so that it wont matter if the finger doesn't end up at the same screen location on the 2nd tap
    4) Listen and react to the tap event from this custom gesture recognizer
     
  4. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    Thanks Spk for the fast response! This sounds exactly like what I wanted, but where do I set the properties such as "Move Tollerance" and "Raise Event on Each Tap"? I havent been able to find them ... or is this soemthing I just need to create in my own class and handle?
     
  5. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    No, you simply create a new empty object in your scene and add the TapGestureRecognizer component to it. Then you can tweak this components properties, as stated in my previous post, and reference the object in the script where you handle the weapon firing on double tap.

    I made a video a while ago that should give you an overview on how to do this (the "advanced method" section).
     
  6. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    Can't thank you enough Spk! Will check this out when I get home. Thanks again!
     
  7. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    You're very welcome! Just doing my support job ;) Let me know how things go.
     
  8. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    Just wanted to thank you again! It worked perfectly! :)
     
  9. shaojingkk

    shaojingkk

    Joined:
    Oct 25, 2011
    Posts:
    10
    Hi, I want ask can fingerGestureManager be disabled by collider, I want to put some thing in front of game to block the game input.
     
  10. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    If you want to disable FingerGestures to block all the finger inputs, you can use the FingerGestures.Instance.enabled property. Set this to false and the FingerGestures singleton will stop processing inputs, thus preventing any gesture recognizer from firing its events.
     
  11. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I'm trying a one, two, and three finger tap. I can't get the event to reliably fire on android.



    Am I doing it right in the sample, just tapping two fingers?

    It seems if I tap a lot with two fingers the event will finally fire.

    But if I wait and just tap two fingers, the event doesn't fire.

    I'm using a Droid-X. Android 2.2.3.

    Do fingers need to be over the purple ball or close together?

    It looks like the sample uses a collider. I bet when I use two fingers it gets confused about where to send the ray cast from. It's probably raycasting from a random point between my two fingers.

    Maybe it would work better doing a raycast using boxes as wide as the area used by my two fingers.
     
  12. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I tried to use a TapGestureRecognizer to detect one, two, and three finger taps. But I didn't see the event fire on Android.

    The static methods OnTop and OnTwoFingerTap seem to work.

    Is it possible that in the next build you could add another static method OnThreeFingerTap?
     
  13. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    I am working on a game that is sort of like bejewled in the way that I pick up the block that is touched and then based on the swipe direction I cast a normal in that direction and pick up the block that it hits and then perform a swap on these two blocks . I am seeing an incorrect swipe occur at times, especially when I start going quickly where i think my finger touches down to the left of the block I am trying to touch and then does a swipe between the far left block and center block, rather than the center block and the right.

    Sorry if that is confusing, but my question is this. First off is there a recommended way of performing this type of action or to say it another way, is there a better way to handle this and secondly, is there a way to control the diameter of my finger touch on the screen. I am unsure if the diameter of the touch point is somethign that is adjustable and perhaps I just need to tweak that instead. I thought that the blocks maybe were too small, but then I was playing bejeweled on my windows phone and they actually are the same and the touch works perfectly on there. This is why im wondering if there is maybe a better way of doing this. If anyone has any recommendations, please send em my way :) Thanks all!
     
  14. imkira

    imkira

    Joined:
    Dec 26, 2011
    Posts:
    39
    Hello xtr33me,
    I am unsure if I understood your question correctly, but if I were you, first I would increase the diameter (width/height/radius,etc.) of your bejewel colliders, not the diameter of the touch point. For instance, suppose you have a matrix of NxN bejewels with 1 box collider per bejewel.
    Secondly, a swipe recognizer is basically a quick drag/drop recognizer. If the user drag&drops past the maximum time allowed for a swipe, you will not get that event I guess. Also, in a typical bejewel user interface you are not usually allowed to drag&drop bejewels in real-time during drag&drop input, only after a valid drop action, right? So I think the moment the finger leaves the source bejewel's collider and enters the target bejewel's collider, since the source bejewel is not moving together with the finger, I think you will not get a "OnDragEnd" event too. I may be wrong here but I would probably use a OnFingerDown and a OnFingerUp on each bejewel. This way, if you get a OnFingerDown on bejewel A and then a OnFingerUp on bejewel C you know that user is trying to move bejewel A over to C (or in the direction from A to C).
     
  15. xtr33me

    xtr33me

    Joined:
    Nov 2, 2011
    Posts:
    90
    Imkira thank you very much for the reply. I was hoping that I wouldn't have to increase the size of the blocks, but kinda was leaning towards that being the solution. Where in bejeweled the moves aren't realtime, mine are :) My blocks are also right next to each other and may be why I am seeing the issue, since they are right near each other. With that being said, I am going to try playing with the colider some and see if there is anything I can do there. I also originally was using the onFingerDown and Up events, but again because of the size of the blocks and the lower accuracy (compared to a mouse on a computer), if the finger wasn't coming up right on one of the adjacent blocks, I wasn't swiping which was fixed when I moved to the swiping. Thanks again for the response :)
     
  16. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Is there a way to detect OnTwoFingerDragMove move on the mac?
     
  17. escpodgames

    escpodgames

    Joined:
    Jan 9, 2012
    Posts:
    9
    I'm trying to use the MoveDelta from a drag but as im using java script, I'm not sure how to convert -

    public:
    property Vector2 MoveDelta {
    Vector2 get ();
    private: void set (Vector2 value);
    }

    any help would be greatly appreciated.
     
  18. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    There should be no differences between PC or Mac; they should be working just the same. Are you having an issue with this?
     
    Last edited: Jan 14, 2012
  19. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Well my macbookpro has a trackpad with multitouch support. Just wondering if it's possible to detect multiple fingers on MacOS.

    You might be limited by the Unity API.
     
  20. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Can you provide more details/context please? Are you using the toolbox scripts, or are you using a non-default gesture recognizer?

    There should be no difference in how the data is accessed in C# or JavaScript. If you have a reference to a DragGestureRecognizer "dragObject" object, you simply call drag.MoveDelta to get the value. It's a property field.

    Code (csharp):
    1. var gesture : DragGestureRecognizer;
    2. var delta : float;
    3. ...
    4. delta = gesture.MoveDelta;
     
  21. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Hm if Unity treats the trackpack as a "touch device" and thus populates the Input.touches array with touch data, then it should simply be a matter of using the "TouchScreen Gestures" implementation of FingerGestures instead of the "Mouse Gestures" one used by default on standalone PC/MAC builds. You can change this in the properties of the "FingerGestures Initializer" prefab/instance.
     
  22. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    I'm using the static events. I need to look over the settings. Even FingerGesture.OnDragMove doesn't seem to fire in the Mac Unity IDE unless I hold the mouse down in the game window. Where it works perfectly on android and iOS.
     
  23. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    This could be a limitation of Unity when it comes to handling the mac trackpad... I don't have one here so it's a bit difficult for me to provide more help on that front. It would be helpful to know if the trackpad is handled as a generic mouse device, or as a touch device by unity (= generates Input.touches).
     
  24. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Of course it depends on the definition of drag move. On Android you have to touch and move to fire the drag move event. On the mac, just moving the track pad isn't considered a drag. You have to click and drag to be considered a drag move.

    It's a slight conceptual difference between the platforms.

    Perhaps there could be another static event, being touch move. That way on both devices it would mean you are touching the screen, dragging without pushing hard.

    Since you don't have a mac to test, here's a video of what it's like.

     
  25. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    It seems pretty generic. I don't see any Input.touches showing on the Mac.

     
  26. jo.nas

    jo.nas

    Joined:
    Jan 10, 2012
    Posts:
    1
    hi,
    is it possible to get fingerGestures to work with unituio?(http://xtuio.com/index.php/projectsmain/utuiomain)
    unituio is using its own iPhoneInput class, but this should be compatible to the standard Input class or not?
    is it possible to transfer the iPhoneInput events to Input?
    if anyone got some experience with fingerGestures and unituio any help would be nice.
    thanks and have a nice day

    jonas
     
  27. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Does android even support 3 fingers? http://stackoverflow.com/questions/5893336/android-3-finger-touch-detection
     
  28. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
    Yeah it seems the case. I took the two finger static events and created three finger static events. The three finger events work on my iOS iPad2 but not android.



    It seems like a limitation of Android 2.3.3.

    Does anybody know how many fingers work on the latest cyanogenmod?
    http://www.cyanogenmod.com/

    The last 3 minutes of the video were truncated by snagit (grrrr!) But here's the script I used to test the three finger static events on Android (fail) and iOS (works).
     

    Attached Files:

    Last edited: Jan 11, 2012
  29. Intrawebs

    Intrawebs

    Joined:
    Mar 24, 2011
    Posts:
    45
    PROBLEM
    While in Unity I had the default max delay between taps and it would only raise 12 out of every 20 tap events (MAC and ipod4). After changing it to 1, it's raised everytime, works great in Unity. But when deployed to the ipod it still only registering 12 of every 20 taps. My setup below is very basic, Im not sure what to do here put I would expect it to work the same on the devices for a simple tap.

    SETUP...

    I have a scene with a camera and FingerGesturesInitializer (v2.2) objects.

    On the camera I have the TapGestureRecognizer (from FingerGestures/Components).
    Its params are as follows...
    StartOfTouchSequence, 1, 0, checked, 1, 0, 5

    My camera has the following script....
    Code (csharp):
    1. // Use this for initialization
    2.     void Start () {
    3.         TapGestureRecognizer tapCompo = GetComponent<TapGestureRecognizer>();
    4.         tapCompo.OnTap += InputOnTap;
    5.     }
    6.    
    7.     // Update is called once per frame
    8.     void Update () {
    9.    
    10.     }
    11.    
    12.     int tapNum = 0;
    13.     void InputOnTap(TapGestureRecognizer tap)
    14.     {
    15.         RaycastHit hit = new RaycastHit();
    16.         Ray ray = Camera.main.ScreenPointToRay(tap.Position);
    17.         tapNum++;
    18.         Debug.Log(tapNum + " TAP " + ray);
    19.     }
     
  30. Intrawebs

    Intrawebs

    Joined:
    Mar 24, 2011
    Posts:
    45
    I have dramatically improved this by setting the Move Tolerance to 100. However, it's still missing the odd tap here and there when I have the DragGestureRecognizer running as well (its tolerance is set to 5).

    Does anyone have some good and tested values that they have found to work well on iOS (ipad, pod, phone)?
     
  31. motiondisabled

    motiondisabled

    Joined:
    Aug 15, 2011
    Posts:
    77
    Hi.

    I'm wanting to detect tap gestures on a collider. Like in your preview video when the screen is tapped it shows the tap count. I was wondering if you can use this to say:

    If (the tap count on this collider/gameobject has reached the required amount) then say (play this animation); for eg?

    If this is possible how will i go about it as im not very good at scripting but your product will help me out greatly.

    Thanks
     
  32. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    The easiest way for you to do this without too much extra coding is to use the toolbox scripts:
    • Make sure you have an object with TBInputManager in your scene
    • Add the TBTap script to your gameobject with the collider, and set its "tapCount" property to the desired number of taps.
    • Optional: setup the Message property with the SendMessage() target object and method to name to use. By default, the script will do a SendMessage("OnTap") on the GameObject it's installed on.
    • Create a new custom script that would look something like that (pseudo code):

    Code (csharp):
    1.  
    2. public class PlayAnimOnTap : MonoBehaviour
    3. {
    4.    // name of the animation to play
    5.    public string animToPlay;
    6.  
    7.    // this method is invoked by the TBTap script via a SendMessage()
    8.    void OnTap()
    9.    {
    10.       // play the animation
    11.       animation.Play( animToPlay );
    12.    }
    13. }
    14.  
    Put this custom script on the object that you want to play an animation on when the desired number of taps occur. If this isn't the same object as the one hosting the TBTap, make sure that you update the TBTap's Message.target property accordingly.
     
  33. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    It's a bit difficult to get a clear idea on where the issue is, as it could be many things: user error (e.g. moving the finger too far from the first tap position in consecutive taps), hardware lag on device, or bug in the code. I've had other reports about people having some issues with the tapping with the latest version, so I'm going to give it a closer look to make sure things are working properly on that front.
     
  34. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Thanks for the video and investigation results :) That will certainly help some of the droid people out there.
     
  35. TimB

    TimB

    Joined:
    Jan 19, 2011
    Posts:
    65
    Is anyone else experiencing pretty big garbage collection spikes inside FingerGestures.Update()?
     
  36. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    When designing the library, I took particular care to not generate any dynamic allocations at runtime, so this seems a little strange. Have you tried deep profiling it, to see if it's an issue with FingerGestures or if it's some of your custom code you have put in a FingerGesture event handler?

    The input events are fired from the FingerGestures.Update() method, which means that your custom event handling code will also be executed from this function. You might have written some code in there that allocates new objects each time the event is fired. This would then look like a spike coming from the FingerGestures.Update() on the profiler.

    Let me know how it goes - it could be a bug in FingerGestures, but that would be a bit surprising to me as this would probably have been reported several times by now.
     
  37. TimB

    TimB

    Joined:
    Jan 19, 2011
    Posts:
    65
    Thanks for the quick reply, I'll dig into my event handlers. It's very possible it's something I'm doing.
     
  38. bobcat53

    bobcat53

    Joined:
    Jul 12, 2010
    Posts:
    26
    Hi SPK, thank you for this awesome package, I've been using it on all of my recent projects and it has been an amazing time saver!

    For my current project I need to pause the game using a two finger swipe down and I'm pausing by setting time.timescale to 0. I would like to be able to use another two finger swipe to resume the game but unfortunately time.timescale also affects finger gestures. Do you have any ideas how I can solve this?
     
  39. MeMM00

    MeMM00

    Joined:
    Jan 18, 2012
    Posts:
    2
    Hey there Spk, i have a problem with using your package(that sounded wrong)

    my boss wants me to be able to dragorbit around a gameobject, but at the same time have a few buttons to the right that have predefined position and rotation values set to them for the camera. and then still be able to to orbit around from that position

    but i cant seem to get this done in any way, do you have any suggestions on where to look, or how i should solve this?
     
  40. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    This is a bit of a tricky situation - I've encountered this case in previous projects. Setting timeScale to 0 will apparently stop all objects from Update()ing. FingerGestures update its input on every frame from FingerGestures.Update() as well. This means that when timeScale is set to 0, touch inputs are no longer being polled and fed to the gesture recognizers.

    I'm not sure if this will work, but you should try to move the FingerGestures.Update() code to a coroutine that ticks on every frame instead.
     
  41. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    The camera position, via the orbit camera script, is controlled by 3 parameters: yaw angle, pitch angle and distance (spherical coordinates). I suggest that you find the set of values that correspond to your predefined camera positions and manually set them on the orbit camera script (via IdealYaw, IdealPitch and IdealDistance properties, if I recall correctly) when pressing one of these buttons.
     
  42. MeMM00

    MeMM00

    Joined:
    Jan 18, 2012
    Posts:
    2
    yeah, i figured it out but thanks anyway.
     
  43. Dan Dixon

    Dan Dixon

    Joined:
    Jan 18, 2012
    Posts:
    4
    We just updated to v2.x from v1.x.

    Two questions:

    1
    We're using OnPinchMove to zoom the camera and OnDragMove to rotate our camera around a fixed point. In v1 you could "pinch" (via the mousewheel) and primary click drag with the mouse at the same time, but FingerGestures_OnPinchMove is not called anymore when a finger is down. Any thoughts on how to fix this or work around this issue?

    ---

    2
    I had modified the code of v1 to pass the tap count and drag state on the Finger up event. This way I could only trigger an action if the finger went up but only if there was no drag OR if it was the up event for the 2nd tap. What's the best way to handle those situations now in v2?
     
    Last edited: Jan 18, 2012
  44. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Hi Spk,

    I see there is code for ValidDirections and Tolerance. Is it possible/have you tried to "get" diagonal swipes?

    (I have bought 2.2 and it's great, now I need another direction, want to know if you have experience doing it)

    Kostas
     
  45. tgraupmann

    tgraupmann

    Joined:
    Sep 14, 2007
    Posts:
    828
  46. Antidote

    Antidote

    Joined:
    Dec 28, 2009
    Posts:
    36
    Hi Spk,

    I try to use Drag finger gestures in javascript but have an issue to convert the screen position to World Position.
    In C++, the line to translate to javascript is : dragObject.transform.position = GetWorldPos(fingerPos);
    Providing the finger gestures samples in javascript would be helpful.

    Thanks for your good work !
     
  47. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Assuming you're running a desktop platform with a mouse, can you check if you are using the MousePinchGestureRecognizer when running? If you take a look at MousePinchGestureRecognizer.CanBegin, it doesn't do any check to see if some fingers are down (and thus prevent the gesture) so in theory you should be able to do both pinchMove and a drag without having one preempt the other one.

    Hm you could access the default gestures states (e.g. FingerGestures.Defaults.Tap and FingerGestures.Defaults.Drag) and query their state (e.g. FingerGestures.Defaults.Taps.State) and other more specific properties (FingerGestures.Defaults.Tap.Taps for the current tap count).

    Let me know if that helped you or not.
     
  48. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    The ValidDriections property of the SwipeGestureRecognizer allows you specify which directions you want the gesture recognizer to treat as valid (and thus which directions to ignore). The SwipeDirection enum contains a list of flags that you can combine to say "Left and Right directions" for horizontal for instance.

    If you need to introduce a new direction, such as a diagonal, you will have to add a new flag entry to this enum, and also update the FingerGestures.GetSwipeDirection() static method to detect the new direction. And I think that's all you need to do, the SwipeGestureRecognizer will do the rest.
     
  49. Bugfoot

    Bugfoot

    Joined:
    Jan 9, 2009
    Posts:
    533
    Hi Antidote,

    In order for me to help you, could you please provide a little more info/context on what you're trying to do? I don't see anything wrong with the line you have posted, as the syntax would work in both C# or Javascript. Could you please copy/paste the errors that the compiler is giving you?
     
  50. Antidote

    Antidote

    Joined:
    Dec 28, 2009
    Posts:
    36
    Hi Spk,

    For the context, what I want to achieve is from a same object to have several gestures recognition, Tap, Drag and Long Press.
    So, I took your javascript scene " PickObject " and try to modify it, first by adding a white sphere and in another hand modifying script. It worked for tap and longpress but not for drag.
    The message that I got is "Assets/FingerGestures/Samples/Scripts/PickObject.js(53,45): BCE0005: Unknown identifier: 'GetWorldPos'."

    Here is the full code :

    ----------------------------------------------------------------------------------
    var textField : TextMesh;
    var dragFingerIndex : int;
    var dragObject : GameObject;


    function OnEnable()
    {
    // register to global single-finger tap event
    FingerGestures.OnFingerTap += FingerGestures_OnFingerTap;
    FingerGestures.OnFingerUp += FingerGestures_OnFingerUp;
    FingerGestures.OnFingerLongPress += FingerGestures_OnFingerLongPress;
    FingerGestures.OnFingerDragBegin += FingerGestures_OnFingerDragBegin;
    FingerGestures.OnFingerDragMove += FingerGestures_OnFingerDragMove;
    FingerGestures.OnFingerDragEnd += FingerGestures_OnFingerDragEnd;
    }

    function OnDisable()
    {
    // unregister from global single-finger tap event
    FingerGestures.OnFingerTap -= FingerGestures_OnFingerTap;
    FingerGestures.OnFingerUp -= FingerGestures_OnFingerUp;
    FingerGestures.OnFingerLongPress -= FingerGestures_OnFingerLongPress;
    FingerGestures.OnFingerDragBegin -= FingerGestures_OnFingerDragBegin;
    FingerGestures.OnFingerDragMove -= FingerGestures_OnFingerDragMove;
    FingerGestures.OnFingerDragEnd -= FingerGestures_OnFingerDragEnd;
    }


    function FingerGestures_OnFingerDragBegin( fingerIndex : int, fingerPos : Vector2, startPos : Vector2 )
    {
    // make sure we raycast from the initial finger position, not the current finger position (see remark about dragTreshold in comments)
    var selection : GameObject = DragObject( startPos );
    if( selection == dragObject )
    {
    DisplayText("Started dragging with finger " + fingerIndex);

    // remember which finger is dragging dragObject
    dragFingerIndex = fingerIndex;

    // spawn some particles because it's cool.
    // SpawnParticles( selection );
    }

    }

    function FingerGestures_OnFingerDragMove( fingerIndex : int, fingerPos : Vector2, delta : Vector2 )
    {
    // var selection : GameObject = DragObject( startPos );
    // we make sure that this event comes from the finger that is dragging our dragObject
    if( fingerIndex == dragFingerIndex )
    {
    // update the position by converting the current screen position of the finger to a world position on the Z = 0 plane
    dragObject.transform.position = GetWorldPos(fingerPos);
    }

    }

    function FingerGestures_OnFingerDragEnd( fingerIndex : int, fingerPos : Vector2 )
    {
    // we make sure that this event comes from the finger that is dragging our dragObject
    if( fingerIndex == dragFingerIndex )
    {
    DisplayText("Stopped dragging with finger " + fingerIndex);

    // reset our drag finger index
    dragFingerIndex = -1;

    // spawn some particles because it's cool.
    // SpawnParticles( dragObject );
    }

    }


    function FingerGestures_OnFingerTap( fingerIndex : int, fingerPos : Vector2, tapCount : int )
    {
    var objTap : GameObject = TapObject( fingerPos );

    if( objTap )
    DisplayText( "You tapped " + objTap.name );
    else
    DisplayText( "You didn't pressed any object" );

    }


    function FingerGestures_OnFingerUp( fingerIndex : int, fingerPos : Vector2 )
    {
    var obj : GameObject = PickObject( fingerPos );

    if( obj )
    DisplayText( "You pressed " + obj.name );
    else
    DisplayText( "You didn't pressed any object" );
    }


    function FingerGestures_OnFingerLongPress( fingerIndex : int, fingerPos : Vector2 )
    {
    var objPress : GameObject = LongPressObject( fingerPos );

    if( objPress )
    DisplayText( "You pressed " + objPress.name + " assez longtemps, au moins 2 secondes !" );
    else
    DisplayText( "You didn't pressed any object" );

    }


    function DisplayText( text )
    {
    if( textField )
    textField.text = text;
    else
    Debug.Log( text );
    }

    function TapObject( screenPos : Vector2 ) : GameObject
    {
    var rayTap : Ray = Camera.main.ScreenPointToRay( screenPos );
    var hitTap : RaycastHit;

    if( Physics.Raycast( rayTap, hitTap ) )
    return hitTap.collider.gameObject;

    return null;

    }

    function DragObject( screenPos : Vector2 ) : GameObject
    {
    var rayDrag : Ray = Camera.main.ScreenPointToRay( screenPos );
    var hitDrag : RaycastHit;

    if( Physics.Raycast( rayDrag, hitDrag ) )
    return hitDrag.collider.gameObject;

    return null;

    }


    function PickObject( screenPos : Vector2 ) : GameObject
    {
    var ray : Ray = Camera.main.ScreenPointToRay( screenPos );
    var hit : RaycastHit;

    if( Physics.Raycast( ray, hit ) )
    return hit.collider.gameObject;

    return null;
    }

    function LongPressObject( screenPos : Vector2) : GameObject
    {
    var rayLong : Ray = Camera.main.ScreenPointToRay( screenPos );
    var hitLong : RaycastHit;

    if( Physics.Raycast( rayLong, hitLong ) )
    return hitLong.collider.gameObject;

    return null;

    }

    ----------------------------------------------------------------------------------