Weird touch input behavior in WebGL (mobile browsers)

Hi everyone,

I’m currently porting my game to WebGL, and I’ve noticed some odd input issues that don’t appear on other platforms.

On Android, touch inputs work flawlessly, but on mobile browsers, I’m experiencing problems. Specifically, touches on the left side of the screen occasionally cause unintended rotation, even when I’m not moving my right finger. The issue seems random, and releasing the right touch momentarily fixes it, but then it happens again after some time.

Has anyone else encountered this kind of behavior with WebGL on mobile browsers? Any insights or suggestions on how to resolve this would be greatly appreciated!

I am using old Input system.
And here is code I am using:

	void UpdateLookRotation(){
		
		float touchRotationX = 0f;
		float touchRotationY = 0f;

		if(mobileInput){
			if(Input.touchCount > 0){
				
				for (int i = 0; i < Input.touchCount; i++)
				{
					Touch t = Input.GetTouch(i);
					if (t.phase == TouchPhase.Moved && t.position.x > Screen.width/2){

						#if UNITY_WEBGL
							touchRotationX = -Input.GetTouch(i).deltaPosition.x;	
							touchRotationY = -Input.GetTouch(i).deltaPosition.y;
						#else
							touchRotationX = Input.GetTouch(i).deltaPosition.x;	
							touchRotationY = Input.GetTouch(i).deltaPosition.y;
						#endif
					}
				}
			}
		}

		//...
	}

Thanks in advance!

Yes! :frowning:

Touch input in WebGL just plain sucks, tons of issues with that.

Try different devices and browsers, and use the default html template. If it’s device or browser specific, you may need to code browser-specific workarounds.

Also make a simple testcase project to ensure it’s not related to some bug in your existing code. Add logging to see what events and values you get. Play with device settings if necessary, such as turning off multi-touch gestures and what not. Also check under settings the browser-related settings to see if it has any input related options and play with those.

Be sure to use the Input System package! Also confirming the input values from javascript may also provide insight as to whether any unexpected values are systemic (Browser or OS).

Be sure to search for other “webgl + touch input” issues. Plenty of threads around that topic.

Note that if you ever get a multi-touch, the touches with higher index will overwrite your input values!

For instance if you were tracking the index finger (assume it’s 0) and at the edge of the screen the device thinks you are multitouching merely due to being at the edge of the screen, then the separate touch will give you incorrect deltas!

You want to track a specific touch, the first one that becomes active (TouchPhase.Began) and that’ll be your index until you get TouchPhase.Ended.

I suppose this particular issue could be self-inflicted. But do expect more. :wink:

1 Like

Hi! I had exactly the same problem, I even sent a bug report, where the problem was confirmed. But! They said that the problem is not a priority and they will not fix it

2 Likes

Could be that this “won’t fix” is due to browsers having that issue to begin with so Unity could at best work around the issue.

Pro tip: be sure to disable multi-touch in WebGL (redesign the input to single touch). There’s a property for that in both input systems, or at least the new one. If you don’t disable it, multitouch will §#@$§! with you every now and then in my experience. It’s been a few years though. :wink: