TouchPhase.Moved interfere with TouchPhase.Ended

Hello forum :slight_smile:

My problem is this. I am trying to differentiate between a tap and a swipe.
Lets say I want to move my camera with a swipe, no problem!
Or I want to tap and do something, again, no problem.

The problem is when I swipe and lift my finger it also counts as a tap.
So I thought of condition, but in my script once I do a swipe, the tap stops working :frowning:
I did a lot search in google, but with no success :frowning:

Is it there a proper way to distinguish between a swipe and a tap and not interfere with each other.

Here is my code in JS
And thank you for your time :slight_smile:

private var Moved : boolean = false;
private var Began : boolean = false;

function Update () {
for (var i = 0; i < Input.touchCount; ++i) {

   var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);    
   var hit : RaycastHit;
  
     if (Input.GetTouch(i).phase == TouchPhase.Moved)
       {
    Moved = true;
        } 
       
          if (Input.GetTouch(i).phase == TouchPhase.Began) 
          {
          Began = true;
          }  
        
        if (Input.GetTouch(i).phase == TouchPhase.Ended) {
         
        if (Began == true  Moved == false ) {
           Moved = false;
           Began = false; 
 
              if (Physics.Raycast(ray,hit)) { 
                    var gunRotate = GameObject.Find("gun_parent").GetComponent(Gun_Rotate); 
                    gunRotate.Turn(hit.point);

                 cooldownGun();
                 explosionSphere();
                 SphereRestart();
                 Began = false;
                 Moved = false;
      }  
    }
   }
  }  
 }

Personally I have a threshold value to distinguish between the two. I track each touch’s current and original positions, and if the current position is ever further away from the original position than the threshold distance I transition it to a swipe and behave accordingly.

Hi angrypenguin, thanks for the response, can you show me an example how you do that?

Hi dear Andrey86, could you solve your old problem? Can you help me what should i do?