Search Unity

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

TouchScript FlickGesture direction detection.

Discussion in 'Scripting' started by GodlyUnderdog, May 19, 2014.

  1. GodlyUnderdog

    GodlyUnderdog

    Joined:
    Feb 2, 2014
    Posts:
    24
    So for anyone who's familiar with the TouchScript pack, I'm having a little trouble here. I'm about to move into doing detailed touch detection alongside it, but I wanted to make sure that I was missing something first. I have a flick gesture set up and working, however, the GestureDirection enum only trackes horizontal or vertical, while I need to access left or right. I've been reading the FlickGesture.cs for awhile, but it seems that any useable data to determine that is either private or cleaned up immediately. So I guess the question is, is there a built in way to know if a flick is left or right or will I have to detect start and end touch positions to determine that myself?
     
  2. GodlyUnderdog

    GodlyUnderdog

    Joined:
    Feb 2, 2014
    Posts:
    24
    Figured it out by using the Gesture.cs NormalizedScreenPosition, and PreviousNormalizedScreenPosition.
     
  3. Fourthings

    Fourthings

    Joined:
    Feb 15, 2010
    Posts:
    313
    How exactly did you do that? I'm trying to work out how to get the direction and velocity of a flick, odd how this is not included in the package
     
  4. ali-but

    ali-but

    Joined:
    Apr 3, 2018
    Posts:
    19
    This is how i manged to do it .
    Attach flick gesture component to game object and give its reference to panelGesture variable
    Code (CSharp):
    1.  
    2. public FlickGesture panelGesture;
    3.  bool isPanelFlickDown;
    4.  
    5. void Start () {
    6.  
    7.         panelGesture.Flicked += panel_Flicked;
    8.  
    9.  
    10.     }
    11.  
    12.     private void panel_Flicked(object sender, System.EventArgs e)
    13.     {
    14.         if (isPanelFlickDown)
    15.         {
    16.             ClosePanel();
    17.         }
    18.      
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update () {
    23.         if (panelGesture.PreviousScreenPosition.y> panelGesture.ScreenPosition.y)
    24.         {
    25.             isPanelFlickDown = true;
    26.         }
    27.         else if(panelGesture.PreviousScreenPosition.y < panelGesture.ScreenPosition.y)
    28.         {
    29.             isPanelFlickDown = false;
    30.         }
    31.  
    32.    }
    33.  
     
unityunity