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
2
Question by pushbyte · Mar 23, 2012 at 12:27 AM · iosmobiletouchtouchphasetouchcount

Input.touchCount returning wrong number

I've been venturing into mobile development lately and am running into an issue with touch input. The touchCount and TouchPhase seem to be returning the wrong information. Here's some skeleton code:

mainCharacter.js

 function Update() {
     var input:float = touchInputScript.getInput();
 }

touchInputScript.js

 var inputDirection:float = 0.0;
 var inputThreshold:float = 5.0;
 
 function getInput():float {
     if(Input.touchCount > 0) {
     var touch = Input.touches[0];
         Debug.Log(Input.touchCount);
         if(touch.phase == TouchPhase.Moved) {
             if (touch.deltaPosition.x < -inputThreshold)
                 inputDirection = -1;
             else if (touch.deltaPosition > inputThreshold)
                 inputDirection = 1;
             else
                 inputDirection = 0;
         }
     } else {
         inputDirection = 0;
     }
     return inputDirection;
 }

This usually works as expected, but frequently it will report the touchCount as 1 even when nothing is touching it at all. This 'ghost finger' is always reported as TouchPhase.Stationary. This has me stumped and is very frustrating. Should I just be running the getInput() function inside of touchInputScript's update() function, storing the state and then checking the variable from mainCharacter.js?

Thanks in advance for any suggestions. :)

Edit

Well, I reduced my code to the following:

 function Update() {
     print(Input.touchCount);
 }

And if I scrub my finger back and forth at a decent speed, touchCount will begin to register 2 (or sometimes more) touches. Once my finger is removed, it will continue to register a single finger on screen. It's very strange and very frustrating.

Comment
Add comment · Show 5
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 DaveA · Mar 23, 2012 at 12:30 AM 0
Share

Sounds like flaky hardware

avatar image pushbyte · Mar 23, 2012 at 01:12 AM 1
Share

Happens on both an iPad and an LG G2X (Android.) It seems more prone to happen with the Unity Remote, but happens (far less frequently) on the hardware.

avatar image kromenak · Mar 23, 2012 at 01:35 AM 0
Share

Where is the touch variable that you are using here? The iPad input functionality has always worked great for us. We have had some issues with it on Android, mostly related to mul$$anonymous$$ch on certain devices.

You might have some luck using a for loop to iterate over all the touches and grab their state info.

int moveTouchId = -1;

for(int i = 0; i < Input.touches.Length; i++) { Touch t = Input.GetTouch(i);

 if(t.phase == TouchPhase.Began && moveTouchId == -1)
 {
     moveTouchId = t.fingerId;
 }

 if(t.phase == TouchPhase.$$anonymous$$oved && t.fingerId == moveTouchId)
 {
     //do your movement code
 }

 if(t.phase == TouchPhase.Ended && t.fingerId == moveTouchId)
 {
     moveTouchId = -1;
 }

}

We've used stuff like this and haven't had any problems.

avatar image pushbyte · Mar 23, 2012 at 01:48 AM 0
Share

I edited my first post to show where I grab the touch variable.

avatar image danieldourado_2 · Jul 16, 2015 at 03:43 PM 0
Share

I am having the same problem with a nexus 5 android 5.0

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

8 People are following this question.

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

Related Questions

How to make function respond to only the initial touch position. 1 Answer

Short question: If my app runs without any problems on Android, should it run without any problems on iOS? 1 Answer

Taps are not detected on mobile 1 Answer

IOS GUI slider 1 Answer

Unity Touch Help! 0 Answers


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