Search Unity

Touch Swiping Issues

Discussion in 'Android' started by CoffeeConundrum, Jun 1, 2014.

  1. CoffeeConundrum

    CoffeeConundrum

    Joined:
    Dec 30, 2013
    Posts:
    46
    Hiya folks!
    Quick question, I've been trying to refine the swiping controls in my latest project and I'm still relatively new to the touch controls for Unity. The project has three lanes that the player can move a box between by the use of swiping. Swiping gestures are working fine just if I'm in lane 1 and wish to swap to the lane next to me i.e. lane 2, when I swipe across my screen it swaps me to lane 3 and vise versa. The only way I can get back into lane 2 again is through a very small and minute swiping gesture. I could be potentially missing something from my code that would help this, this is how I have the main update function for the square set up.
    Code (csharp):
    1. if (Input.touchCount > 0  Input.GetTouch (0).phase == TouchPhase.Moved)
    2.         {
    3.             /* Moves the square everywhere depending on the length of swipe */
    4.             //Get the movement from last frame
    5.             Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
    6.             /****************************************************************/
    7.  
    8.             /* Trying to move the square by a set amount to move through lanes */
    9.             if (touchDeltaPosition.x > 1  currentLane < 3)
    10.             {
    11.                 //Swiped right
    12.                 currentLane++;
    13.                 MoveLane(currentLane);
    14.            
    15.             }
    16.             else if (touchDeltaPosition.y < 1  currentLane > 1)
    17.             {
    18.                 //Swiped left
    19.                 currentLane--;
    20.                 MoveLane(currentLane);
    21.  
    22.             }
    My move lane function just takes in the lane that the square should be in and moves the squares position to be of that respective lane.
    Many thanks for any help!
     
  2. jgb143

    jgb143

    Joined:
    Jun 8, 2010
    Posts:
    132
    Swiping one way you're using touchDeltaPosition.x, the other way touchDeltaPosition.y

    I'd guess you'd want to use x for both of those. Does swiping up (or is it down) get you back to the other lanes?