# Swipe Movement On A Grid

I’m making a game like tetris for mobile devices. It’s movement should be on a grid. When i swipe right or left, the object moves 1 unit to right or left. No matter how much i drag it, it just moves 1 unit. But i want it to move more than 1 unit if i drag it longer. How can i achieve that? The game Tetris in google play store uses the method i want but i dont know how they did it. So please help.
Here is the script that makes it move once:

``````    private bool fingerDown;
public Vector2 startPos;
public int pixelDistToDetect = 41;

// Update is called once per frame
void Update()
{
if(!fingerDown && Input.GetMouseButtonDown(0))
{
startPos = Input.mousePosition;
fingerDown = true;
}
if (fingerDown)
{
if(Input.mousePosition.x >= startPos.x + pixelDistToDetect)
{
fingerDown = false;
gameObject.transform.position += new Vector3(0.82f, 0, 0);
startPos = Input.mousePosition;
return;

}
if (Input.mousePosition.x <= startPos.x - pixelDistToDetect)
{

fingerDown = false;
gameObject.transform.position -= new Vector3(0.82f, 0, 0);
startPos = Input.mousePosition;
return;

}
}

if(fingerDown && Input.GetMouseButtonUp(0))
{
fingerDown = false;
}
``````

i made it with mouse input for testing. It will be touch input in the final.

I think your problem lies with the fact that you have “fingerDown = false” on line 17 and line 26. The logic is fine, you check if the finger is down and if the finger is down you check the distance between the starting point and the current position. If the distance is greater than the set value, you move the object and set a new start point.

BUT! , this is not an indication the player has removed their finger from the screen and therefore, fingerDown should still be true to register the movement, otherwise it will only start tracking again if the player puts a finger back on the screen, because that is the only point in your code where fingerDown is set to true.