Touch input left and right

So I’ve been trying to figure this all out in multiple different ways but with no success. What I’m trying to do is make it so if your finger is always on the screen, then begins to move left or right it will call the code accordingly. Which in my case the current and previous touch locations as you move should be recorded. I’ve done some debugging and the delta position always remains near zero while the current position is always way higher. Is there an easy way to keep track of the position that your finger just moved from and the new position?

    if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
       
                touch1 = Input.GetTouch(0).position;
                touch2 = Input.GetTouch(0).deltaPosition;

                if(touch1.x > touch2.x) {
           
                    //move right
           
                }
                else if(touch1.x < touch2.x) {
           
                    //move left
           
                }
            }

Deltaposition is the change in the position, not the previous position. If you move from ‘100’ to ‘101’ the delta is 1, not 100. Previous position would be current plus (or maybe minus? Whichever) the delta.

I think you can just check if the deltaposition.x is greatthan or lessthan 0

1 Like

That makes a lot more sense. I will try that out and let you know

Edit. Worked perfect! Thank you