Detecting Quarter Circle Swipes

Hello,

Currently I’m working on swipe detection controls just to test them out. I currently have it detecting 8 way swipe, and very limited quarter circle swipe. What I mean by this is that it will pick up that a quarter circle is a happening in one direction but not another. For example Quarter circle back is detected when a finger is moved in a quarter circle up and to the left (negative movement on the x axis and positive movement on the y axis). Trying any other way will cause another quarter circle swipe to be detected. Attached is a snippet of code as to how the detection works. Any help would be greatly appreciated.

if (t.phase == TouchPhase.Moved) {
                position.Add (new Vector2 (t.position.x, t.position.y));

            }

            if (t.phase == TouchPhase.Ended) {
                if (t.fingerId == finIdL) {
                    secondPressPos = new Vector2 (t.position.x, t.position.y);
                    position.Add (new Vector2 (secondPressPos.x, secondPressPos.y));
                    currentSwipe = new Vector3 (secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);
                    StarttoMid = new Vector3 (position [z/ 2].x - firstPressPos.x, position [z / 2].y - firstPressPos.y);
                    MidtoEnd = new Vector3 (secondPressPos.x - position [z / 2].x, secondPressPos.y - position [z / 2].y);
                    Total = StarttoMid.magnitude + MidtoEnd.magnitude;
                    finIdL = -1;
                    CoordinateX.LX = currentSwipe.magnitude;
                    CoordinateY.LY = Total;
                    compare = currentSwipe.magnitude;
                    position.Clear();
                }
            }

            if (currentSwipe.magnitude < minSwipeLength)
            {
                SwipeText1.Ltouchtype = "LTap";
                leftSwipe = LSwipe.LTap;
                return;
            }

else if (currentSwipe.y > 0 && currentSwipe.x < 0)
            {
                if (Total > compare+buffer)
                {
                    SwipeText1.Ltouchtype = "LQCB";
                    leftSwipe = LSwipe.LQCB;

                }
                else
                {
                SwipeText1.Ltouchtype = "LSUL";
                leftSwipe = LSwipe.LUpL;

                }

It appears you are only ever setting Total to the sum of two .magnitude properties.

Magnitudes will always be non-negative, so the only way the “LSUL” else case will happen is if the two magnitudes are zero, which does not seem likely, or perhaps only appears as a transient single-frame condition.

I understand where you are coming from, though this is not the case. Total is the sum of two vectors you are correct, but compare the the magnitude of a single vector in addition to a buffer to allow LSUL to run. Total is built from the start point to the mid point (using a list to detect the swipe position of the finger) and then from the mid point to the end point, where as compare is simply the start and end point.

I was a bit tired when writing the post and reading it back I realise that it doesn’t exactly convey my problem. I have an 8 way swipe working, in addition to a clockwise quarter circle (so for example moving up and left will detect LQCB). The problem I am having is when attempting to have these gestures recognised in a counter clockwise direction they are detected as mirrored due to the way the current code is set up (so for example moving down and right in the current code will detect LQCD.)

Would there be a way in the current set up to fix this, or would detection have to involve dot products and angles rather than simple determining coordinates?

Thanks

I have not personally studied the idea of detecting the leftishness or rightishness of a curving swipe. I know there are a LOT of people who have studied this though, so look for posts about it on the broader internet. It’s a problem that has been around since the Apple Newton. I remember seeing it discussed in 2000 with PalmPilot games detecting curving gestures, but I forget how they did it.

Thanks for the info, I’ll look into it, I have found a work around but its a poor mans version with low accuracy

StarttoMid x MidtoEnd will gives you the direction of the swipe

Vector3(position[z /2].x,position[z /2].y); will gives you the quarter