Touch in WebGL on Windows, STILL broken?

Hey, I’m having troubles getting touch to work in WebGL.

In 5.2, touch did not work at all in WebGL, on Windows. It now works, but not correctly - It’s acting very strange.
I’ve built a WebPlayer version, and a WebGL version, of the program and they act very differently. The WebPlayer version acts exactly as predicted, and expected; while the WebGL version acts erratic and weird. The scene only contains a cube, that can be rotated by dragging your finger across the canvas.

WebPlayer version:

I drag my finger across the canvas, and the cube rotates, follwing my finger nicely. I lift my finger, and place it somewhere else - The cube does not move. I begin dragging from the new point, and the cube rotates again. All good.

WebGl version:

I place my finger on the Canvas, and the cube snaps to an akward diagonal angle and begins rotating on it’s own, while jittering slightly. I drag my finger across the canvas and the cube snaps to another orientation, then rotates, while jittering a lot. I release my finger and place it somewhere else, expecting nothign to happen. Instead the cube again snaps to a completely different orientation; and holding my finger on the canvas makes it rotate on it’s own. My best guess at the issue, was that DeltaPosition wasn’t getting reset correctly, but I’ve tried calculating DeltaPosition manually, with no change.

Any ideas? This is the code I use:
float rotationX = 0;
float rotationY = 0;

if (Input.touchCount == 1)
        {
            rotationX -= Input.GetTouch(0).deltaPosition.x * Time.deltaTime * 30f;
            rotationY += Input.GetTouch(0).deltaPosition.y * Time.deltaTime * 30f;
            cube.transform.eulerAngles = new Vector3(rotationY, rotationX, 0);
}

WebGL link: http://demo.cadpeople.com/cubetest/

WebPlayer link: http://demo.cadpeople.com/cubetest2/

Thanks for your time

I am finding the same problem in Unity 2017. Anyone have a solution?

I had the same problem in Unity 2018 with a WebGL running on Chrome.
It seems like in WebGL, the deltapositions (in the update function) are working differently than in Unity itself, because they are incrementally adding something. That’s probably the reason, why your cube keeps rotating “on its own”.


I found a workaround, where I replaced the Touch.deltaPosition and calculated it on my own. So in your example, it should work with this:

float lastX;
float lastY;

if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
    {
    lastX = Input.GetTouch(0).position.x;
    lastY = Input.GetTouch(0).position.y;
    }
        

if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved)
    {
    float deltaX = Input.GetTouch(0).position.x - lastX;
    float deltaY = Input.GetTouch(0).position.y - lastY;

    rotationX -= deltaX * Time.deltaTime * 30f;
    rotationY += deltaY * Time.deltaTime * 30f;
    cube.transform.eulerAngles = new Vector3(rotationY, rotationX, 0);

    lastX = Input.GetTouch(0).position.x;
    lastY = Input.GetTouch(0).position.y;
    }

This should also prevent the gameobject from snapping anywhere just by placing your finger on the screen.