[SOLVED] Unity: Bizarre multitouch behaviour
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:
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
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.
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....... :/
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?
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!!