Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by MikeyPB · May 26, 2021 at 01:32 AM · androidtouch controlstouchscreenmultitouchdragging

Why is my first touch interpreted as a mouse click?

I made this video that demonstrates the problem (60s total, I get to the point in 10s) https://youtu.be/tRrZ1qJzmFw

A description for those who prefer to read:

I have several rectangles on the screen and I wish to move them individually using multitouch. My code looks like this:

  void Update()
     {
     // ** Touches ** \\
         tapCount = Input.touchCount;
         if (Input.touchCount > 0){ //Look through all the touches
           for ( int i = 0 ; i < tapCount ; i++ ) 
             {
                 Touch touch = Input.GetTouch(i);
                 switch (touch.phase){
                     case TouchPhase.Began:
                         if (getTouchedMagnet(touch.position) != null){
                             //getTouchedMagnet compared the touch position with a list of magnets and checks if the touch point is inside any of the magnets. It also logs which touch point is touching the magnet in an int.
                             getTouchedMagnet(touch.position).startTouch(i, touch.position);
                         }
                         break;
                     case TouchPhase.Moved:
                         if (getMagnetByInt(i) != null){
                             //update the position as the touch is moved. getMagnetByInt gets the magnet touched by this touch point
                             getMagnetByInt(i).updatePosition(touch.position);
                         }
                         break;
                     case TouchPhase.Ended:
                         if (getMagnetByInt(i) != null){
                             //set the magnet back to default
                             endInput(i);
                         }
                         break;
                     default:
                 //         Debug.Log("checking touch "+i+" but nothings happening");
                         break;
                         
                 }
             }
         }
         else{ //if no touches are active 
             foreach(Magnet magnet in magnets){
                 if (magnet.touchedBy !=99){ // end all touches(except mouse input) in case touch ends aren't registered
                     magnet.endTouch();
                 }
             }
         }
     // ** Mouse ** \\
     if (Input.GetMouseButtonDown(0) && getTouchedMagnet(Input.mousePosition) != null){
         //get magnet by position and set it to 'mouse' int value to find later
             getTouchedMagnet(Input.mousePosition).startTouch(99, Input.mousePosition);
     } 
     else if (getMagnetByInt(99) != null && Input.GetMouseButton(0)){
         //whilst mouse is active, upate position of magnet touched by mouse
         getMagnetByInt(99).updatePosition(Input.mousePosition);
     }
     else if (getMagnetByInt(99) != null && Input.GetMouseButtonUp(0)){
         //set magnet back to default
         endInput(99);
     }        }

The Problem When using multitouch, the position of first item I touch is set to an average of all the total touch points instead of the actual position of the first touch point. Subsequent items and touches work as I intended - the position is set under the actual touch point.

Again, the video does a much better job of explaining this https://youtu.be/tRrZ1qJzmFw - you'll see the issue within 10s

Things that might be important:

  • These objects are positioned using the Canvas UI (for carefully considered reasons)

  • I have a touch screen laptop and I see this in the Unity Editor in Windows 10 90% of the time

  • I see this on Android device 100% of the time, but have not tested iOS

EDIT I solved this on device by deleting my "mouse" code. I think that Unity is treating my first touch as a mouse input. I understand that its trying to be helpful. Instead of Input.GetMouseButtonDown() Is there a way to say Input.GetMouseButtonDownButCheckItsDefinitelyNotATouch() ?

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

163 People are following this question.

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

Related Questions

How can convert keyboard controller to touchscreen(android .ios ...etc) 1 Answer

Unity 2d android game How to "freeze" position on Y axis 1 Answer

Vector3.back not working 2 Answers

How to replace KeyCode.Space with a simple tap on Android? 1 Answer

Touchscreen Movement?? 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