# Swipe movement help

I know questions regarding swipe movement are very common. But I assure you I have been through over 10 threads, multiple tutorials and what not and am unable to answer this question.

I have a player that moves around the gameboard, by a fixed distance, depending on which direction you swipe in.

Here is the current swipe script I’m using

``````void touchcheck()
{
if(Input.touchCount == 1)
{

//its always x=-1 and y=-1 if touchCount == 0 Resets
if(deltaPosition.x == -1 && deltaPosition.y == -1)
deltaPosition = Input.GetTouch(0).position; //First touch  point stored
afterDeltaPosition = Input.GetTouch(0).position;//the swiping points
angle = Mathf.Atan2(afterDeltaPosition.y-deltaPosition.y,afterDeltaPosition.x -deltaPosition.x)* 180/Mathf.PI ; // angle in degrees from 0,-180 and 0,180)
Debug.Log("Angle "+ angle);

//right swipe
if(angle < 45f && angle > -45f && !restrictR)
{

if(Physics.Raycast(transform.position,Vector3.right,out righthitter))
{
restrictR = true;
right = true;
R = righthitter.distance;
RightObj = righthitter.collider.gameObject;
if(RightObj.tag=="interactable_tile")
{
R = R +1f;
}
if(R >= 1f)
MoveRight();
}

}

//front swipe
else if(angle < 135f && angle > 45f && !restrictF)
{
restrictF = true;
forward = true;
if(Physics.Raycast(transform.position,Vector3.forward,out fronthitter))
{
F=fronthitter.distance;
FrontObj = fronthitter.collider.gameObject;
if(FrontObj.tag=="interactable_tile")
{
F=F+1f;
}
if(F >= 1f)
MoveFront();
}
}

//left swipe
else if(angle > 135f && angle < -135f && !restrictL)
{
if(Physics.Raycast(transform.position,Vector3.left,out lefthitter))
{
restrictL = true;
left = true;
L = lefthitter.distance;
LeftObj = lefthitter.collider.gameObject;
if(LeftObj.tag=="interactable_tile")
{
L = L +1f;
}
if(L >= 1f)
MoveLeft();
}
}

//back swipe
else if(angle > -135f && angle < -45f  && !restrictB)
{
if(Physics.Raycast(transform.position,-Vector3.forward,out backhitter))
{
restrictB = true;
backward = true;
B=backhitter.distance;
BackObj = backhitter.collider.gameObject;
if(BackObj.tag=="interactable_tile")
{
B=B+1f;
}
if(B >= 1f)
MoveBack();
}
}

}
else if( Input.touchCount == 0)
{
if(deltaPosition.x != -1 && deltaPosition.y != -1)
{
deltaPosition.x=-1;
deltaPosition.y=-1;
}
}
}
``````

The problem with this is,
The left swipe DOES NOT WORK. If you swipe to the left, it does the same as a right swipe.

I want my swipe to end when I move my finger a certain distance across the screen. Currently what’s happening is, I can do 2 swipes really fast, and confuse my game to move the player in a weird fashion.

Also, is there a way to get the user to remove his finger before he can start another swipe?

//left swipe
else if(angle > 135f && angle < -135f && !restrictL)

No value of angle can ever be greater than 135 and less than -135. Did you mean || instead of && ?