Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by cadpeople · Jun 06, 2016 at 03:06 PM · touchwebglwindows5.3windows 7

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cadpeople · Jun 15, 2016 at 12:20 PM 0
Share

Bumping..?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DgreenSMT · Dec 20, 2017 at 04:30 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by addiadriano · Jun 07, 2018 at 12:16 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Windows 7 touch not working correctly in WebGL! 1 Answer

Debugging WebGL/Windows Standalone 0 Answers

WebGl on UC Browser 1 Answer

I try to Create a DLL for get WM_TOUCH windows message! 1 Answer

Does unity now support multitouch directly in windows? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges