Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 lukewilliams · Feb 22, 2014 at 08:55 PM · androidiphonemultitouch

Differentiating between fingers in multitouch

Sorry if the question title was vague/misleading/confusing, but I didn't know how else to write it. Say I have two fingers touching the screen, if one is pressing and holding, and the other is swiping, how can I determine which finger is doing which? As in, which one is Input.GetTouch(0), and which is Input.GetTouch(1)? Is there a way to figure it out so I can do both actions at once? That way if one finger is pressing and holding (say to continuously fire a weapon), and then another one goes to swipe (to rotate the camera), I'd be able to do both without confusing the script. And then if the one that is firing the weapon slides a bit, it would keep firing and wouldn't affect the rotation of the camera. All ideas welcome. Thanks.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Owen-Reynolds · Feb 22, 2014 at 10:00 PM

A cheap method is to start out by remembering "touch[0] is doing this" and "touch[1] is doing that." I've noticed the touches are stable on a iPad. In other words, if you touch with thumb then pinky, pinky will always be touch[1].

The tricky part is, if they let go of the first finger, the second finger drops down to be touch[0]. So, if you have two touches and touch[0] ends (which you can check,) copy your saved second finger status into first finger.

If some smart guy touches three times and releases #0, bad things might happen. May have to add "if touches more than 2, ignore all until touches drops down to 0."

Another way, more heavy-duty, is to use the touchID. It's assigned on touchBegin and will never change over the touch. But, an iPad at least, will reuse the lowest free one (I think.) Exs:

 tap and hold 1st finger: touch[0] has ID 0
 tap and hold 2nd finger: touch[1] has ID 1
 Release 1st finger: 2nd finger is now touch[0], but still has ID 1

 Release all fingers, touch again: touch[0] has ID 0 (reuses IDs)

You can "track" any touch, even though it may drop down from [2] to [1] to [0] (I've never seen one go up) by the ID.

Comment
Add comment · Show 5 · 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 lukewilliams · Feb 24, 2014 at 02:26 AM 0
Share

I assume you mean fingerID... do you know how to use it though? I can't figure it out from the reference. For example, how would I find out position of fingerId(1)? Sorry for the late reply, and thanks for your help :)

avatar image lukewilliams · Feb 24, 2014 at 02:28 AM 0
Share

And does it all have the same phase properties i.e. can I still use fingerId.phase == phase.moved or whatever?

avatar image Owen-Reynolds · Feb 24, 2014 at 03:04 AM 0
Share

The ID isn't an index. You have to do all the work yourself. When you see the touch began, save the ID. Each frame after that, the touches loop can compare IDs to your saved ID1 or ID2. Or backwards, search the touches array for your saved ID.

But if the # of touches hasn't changed, and nothing has begun, no need.

avatar image lukewilliams · Feb 24, 2014 at 02:26 PM 0
Share

Thanks Owen, took a bit of going but I got it sorted. Thanks for your help.

avatar image petey · Jan 04, 2016 at 02:38 AM 0
Share

Awesome! I hadn't realised there was such a thing as Touch.fingerId. This saved me so much messing around. You RoCk! Thanks!

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

22 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

Related Questions

How to press 2 buttons at the same time 1 Answer

Deploying to Android or iPhone device - track public variables in inspector? 1 Answer

Specular Materials on iPhone or Android? 1 Answer

Simultaneous Android and iOS development 1 Answer

Is this the correct walkthrough to get a game from pc to android/iphone? 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