[SOLVED] Unity: Bizarre multitouch behaviour

edited in General
This is a really weird behaviour:

What I need:
Left side of the screen steers, right side of the screen has buttons that do other stuff.

What I have:
Left touch steers, but when I touch the right side, the touch on the left loses track.

Bizarro behaviour:
If I put two or more fingers on the screen FIRST, then start steering on the left side, THEN add more touch points, the steering does NOT get interrupted. One finger first doesn't prevent the interruption, only two or more.

The last line is a debug that tracks the number of fingers on the screen and the fingerId of the movement finger. Both numbers track correctly.

Why!??! Help!!! Thanks!!!

My code:
for (int i = 0; i < Input.touches.Length; i++)
		{
			//if no fly finger assigned and touch is on the left side
			if ((flyFingerId == -1))
			{
			if (Input.GetTouch(i).position.x < Screen.width/2)
				{
				switch (Input.GetTouch(i).phase) 
					{
					case TouchPhase.Began:
						// code to run when touch begins here...
						controlType = UseControlType.Mouse;
						touchPointStart = Input.GetTouch(i).position;
						flyFingerId = Input.GetTouch(i).fingerId;
						break;
					}
				}
			} else
				if (Input.GetTouch(i).fingerId == flyFingerId)
			{
				switch (Input.GetTouch(i).phase)
				{
					case TouchPhase.Moved:
					case TouchPhase.Stationary:
					// code to run when touch is being dragged here...
					touchPointOffset = touchPointStart - new Vector2(Input.GetTouch(i).position.x, Input.GetTouch(i).position.y);
					break;
					case TouchPhase.Ended:
					case TouchPhase.Canceled:
					flyFingerId = -1;
					touchPointStart = Vector2.zero;
					break;
				}
			}
		}

		Debugui.text = "touches: " + Input.touches.Length.ToString() + " / flyfingerID:" + flyFingerId.ToString();

Comments

  • edited
    I tested the previous code you had in the other thread on my S7, and it worked fine. I had the offset and flyFingerId write to a label in update, and it would constantly poll out no matter if I touch more fingers.

    I only had an issue similar to what you explained there when I thought the width of the screen would be landscape wise, but running the app in portrait mode the width is down the middle portrait wise.
    So I held my phone side ways, as you do for most fly type games, but then I had the weird interruption issue. I then held the phone upright, and then assuming the right side of the screen in portrait mode the area for the other fingers, it worked fine.
  • vince said:
    I tested the previous code you had in the other thread on my S7, and it worked fine. I had the offset and flyFingerId write to a label in update, and it would constantly poll out no matter if I touch more fingers.

    I only had an issue similar to what you explained there when I thought the width of the screen would be landscape wise, but running the app in portrait mode the width is down the middle portrait wise.
    So I held my phone side ways, as you do for most fly type games, but then I had the weird interruption issue. I then held the phone upright, and then assuming the right side of the screen in portrait mode the area for the other fingers, it worked fine.
    Thanks for this! I checked out if orientation was giving me any trouble by compiling to auto rotate and it still has the same behaviour, so it doesn't seem like that's the problem (I default to landscape left so there's no auto rotation for me)

    I took away the left of the screen check and it's pretty much the same - the move finger would get interrupted if it was not a at least the third finger down....... :/
  • TRIED. EVERYTHING. AM. DESPERATE D:
  • Tried your new code as well. Seems to work, I constantly write the touchoffset to the gui, and it doesn't seem to stop responding. Here's a hacky vid: https://drive.google.com/open?id=1kAqhF4he3MTGPfjX3-Oy4JAjcUiM4M-2

    I touch the left side and begin the tracking, and then I can touch additional fingers and it keeps polling without stopping. Not sure if that tests what you say is going wrong in yours? Does it do the same for you if you do something similar?
    Thanked by 1Tuism
  • Thanks for going through the lengths to try it out, I'm guessing then it's not that bit of code that's fucking up, I'll have to dig around some more, but thanks for confirming about *that* bit of the code! :)
  • CASE CLOSED!!! Thanks @Chippit for discovering the thing that I would NEVER HAVE KNOWN TO LOOK FOR.

    Apparently a Unity default of simulating mouse clicks as touches was messing with my code which could simultaneously work with touch, Daydream controller and keyboard. So this was all that was needed to fix it:

    Input.simulateMouseWithTouches = false;

    OMG!!!! Thank you thank you @Chippit!!
    Thanked by 1Elyaradine
Sign In or Register to comment.