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
0
Question by infinitypbr · Jul 18, 2014 at 08:43 PM · touchfingerid

Input.GetTouch seems to lose the finger and replace it with the next # -- Video & code example.

Hey everyone. I'm using the code below to work the movement of the player on touch devices. It almost always works, and for weeks at a time there'll be no issues. but then all of a sudden, and a bunch today, it starts "skipping" (best word I can think of), where the ID # of the finger is lost and quickly replaced by a subsequent #, even though there is only one finger on the screen.

In the video the last line shows [Finger ID Number] | [Number of Fingers]. ID# 9 is the "no finger" ID, so it should read "9 | 0" or "0 | 1" at all times, since there is only one finger. (sometimes I've seen, but I didn't catch it for the video, the screen display that there are 2 or 3 fingers, even though only one is touching the screen). The last 5 seconds or so of the video shows the joystick circle (covered by my thumb some of the time). The finger doesn't come off the screen, but you can see the circle jump around as the script thinks the finger is off the screen then on in the next frame as a new finger ID.

Any ideas why this may be happening? I'm including the code, which seems solid to me and works almost all the time.

Thanks!

VIDEO: http://www.sfbaystudios.com/joystickissue.mov

CODE:

 for (var i = 0; i < Input.touchCount; ++i) 
         {
             if (Input.GetTouch(i).phase == TouchPhase.Began)
             {
                 var foundHitTouchBegan        : boolean        = false;
                 var touchHitBegan             : RaycastHit;                                                            
                 var touchRayBegan             : Ray             = guiCamera.ScreenPointToRay (Input.GetTouch(i).position);        
                 if (Physics.Raycast (touchRayBegan, touchHitBegan, 10000))   
                 {
                     if (touchHitBegan.collider.gameObject.name == "Mini Map Plus" || touchHitBegan.collider.gameObject.name == "Mini Map Minus")
                     {
                         foundHitTouchBegan = true;
                         touchHitBegan.collider.gameObject.GetComponent(minimapZoom).ZoomCamera();
                     }
                     if (touchHitBegan.collider.gameObject.tag == "guiButton" && !foundHitTouchBegan)
                     {
                         var touchDownName = touchHitBegan.collider.gameObject.name;
                         if (touchDownName == "Camera Circle Right")
                         {
                             cameraRightFingerID = Input.GetTouch(i).fingerId;
                             mainCamera.GetComponent(SmoothFollow).angleOffsetX -= 5;
                         }
                         else if (touchDownName == "Camera Circle Left")
                         {
                             cameraLeftFingerID = Input.GetTouch(i).fingerId;
                             mainCamera.GetComponent(SmoothFollow).angleOffsetX += 5;
                         }
                         else if (touchDownName == "Camera Circle Down")
                         {
                             cameraDownFingerID = Input.GetTouch(i).fingerId;
                             mainCamera.GetComponent(SmoothFollow).angleOffsetY -= 0.5;
                         }
                         else if (touchDownName == "Camera Circle Up")
                         {
                             cameraUpFingerID = Input.GetTouch(i).fingerId;
                             mainCamera.GetComponent(SmoothFollow).angleOffsetY += 0.5;
                         }    
                         else if (touchHitBegan.collider.gameObject.name == "MiniMapSpot")
                         {
                             touchHitBegan.collider.gameObject.GetComponent(toggleMap).GotHit();
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button 1")
                         {
                             if (isNotAttacking)
                             {
                                 attackFingerID     = Input.GetTouch(i).fingerId;
                                 isNotAttacking = false;
                                 playerObject.GetComponent(playerScript).ButtonPressed(1);
                             }
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button 2")
                         {
                             button2FingerID     = Input.GetTouch(i).fingerId;
                             playerObject.GetComponent(playerScript).ButtonPressed(2);
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button 3")
                         {
                             button3FingerID = Input.GetTouch(i).fingerId;
                             playerObject.GetComponent(playerScript).ButtonPressed(3);
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button 4")
                         {
                             button4FingerID = Input.GetTouch(i).fingerId;
                             playerObject.GetComponent(playerScript).ButtonPressed(4);
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button 5")
                         {
                             button5FingerID = Input.GetTouch(i).fingerId;
                             playerObject.GetComponent(playerScript).RightTriggerAction();
                         }
                         else if (touchHitBegan.collider.gameObject.name == "GUI Button Menu Open")
                         {
                             menuOpen = 5;
                             menuOpenButton.SetActive(false);
                             menuCloseButton.SetActive(true);
                             guiMenu.SetActive(true);
                             if (miniMap)
                                 miniMap.SetActive(false);
                             titleController.GetComponent(titleControl).paused     = true;
                             gameOn                                                 = false;
                             unpauseGame                                         = false;
                             playerCamera.camera.enabled                         = false;
                             guiMenu.GetComponent(guiMenuMain).LoadMenu();
                         }
                         foundHitTouchBegan = true;
                     }
                 }
                 if (!foundHitTouchBegan && !controllerUp)
                 {
                     joystickFingerID                = Input.GetTouch(i).fingerId;
                     controllerUp                     = true;
                     var screenPosLTouch             = Input.GetTouch(i).position;
                     var worldPosLTouch                 = guiCamera.ScreenToWorldPoint(screenPosLTouch);
                     worldPosLTouch.z                 = 120.5;
                     JoystickObject                     = Instantiate(JoystickController, worldPosLTouch, Quaternion.identity);
                     var JoystickTransformTouch         = JoystickObject.transform;
                     JoystickTransformTouch.parent     = transform; 
                     joystickCenterX                 = JoystickObject.transform.position.x;
                     joystickCenterY                 = JoystickObject.transform.position.y;
                 }
             }
             else if (Input.GetTouch(i).phase == TouchPhase.Moved || Input.GetTouch(i).phase == TouchPhase.Stationary)
             {
                 var foundStationary = false;    
                 if (cameraRightFingerID     == Input.GetTouch(i).fingerId)
                     mainCamera.GetComponent(SmoothFollow).angleOffsetX -= 5;
                 else if (cameraLeftFingerID == Input.GetTouch(i).fingerId)
                     mainCamera.GetComponent(SmoothFollow).angleOffsetX += 5;
                 else if (cameraDownFingerID == Input.GetTouch(i).fingerId)
                     mainCamera.GetComponent(SmoothFollow).angleOffsetY -= 0.5;
                 else if (cameraUpFingerID     == Input.GetTouch(i).fingerId)
                     mainCamera.GetComponent(SmoothFollow).angleOffsetY += 0.5;
                 else if (joystickFingerID == Input.GetTouch(i).fingerId)
                 {
                     foundStationary            = true;
                     var screenPos2Touch     = Input.GetTouch(i).position;
                     var worldPos2Touch         = guiCamera.ScreenToWorldPoint(screenPos2Touch);
                     joystickCenterX         = JoystickObject.transform.position.x;
                     joystickCenterY         = JoystickObject.transform.position.y;
                     currentTouchX             = worldPos2Touch.x;
                     currentTouchY             = worldPos2Touch.y;
                     var centerTouch         = Vector2(joystickCenterX, joystickCenterY);
                     var currentTouch         = Vector2(currentTouchX, currentTouchY);
                     var dstTouch             = Vector2.Distance(centerTouch, currentTouch);
                     var horizontalTouch     = currentTouchX - joystickCenterX;
                     var verticalTouch         = currentTouchY - joystickCenterY;
                     if (dstTouch > 2)
                     {
                         var vectTouch : Vector2 = centerTouch - currentTouch;
                         vectTouch = vectTouch.normalized;
                         vectTouch *= (dstTouch-2);
                         moveX = (currentTouchX - joystickCenterX) + vectTouch.x;
                         moveY = (currentTouchY - joystickCenterY) + vectTouch.y;
                     }
                     else
                     {
                            moveX = currentTouchX - joystickCenterX;
                         moveY = currentTouchY - joystickCenterY;
                     }
                     var angleTouch : float = Mathf.Atan2(moveX, moveY) * Mathf.Rad2Deg;
                     if (!playerObject.GetComponent(playerScript).isDead)
                     {
                         if (isNotAttacking && isNotDefending)
                         {
                             playerObject.GetComponent(playerScript).angle = angleTouch + mainCamera.GetComponent(SmoothFollow).angleOffsetX;
                             playerObject.GetComponent(playerScript).moveSpeed = dstTouch;
                         }
                     }
                 }
             }
             else if (Input.GetTouch(i).phase == TouchPhase.Ended)
             {
                 //print ("Touch " + Input.GetTouch(i).fingerId + " Phase Ended");
                 if (cameraRightFingerID     == Input.GetTouch(i).fingerId)
                     cameraRightFingerID = 9;
                 else if (cameraLeftFingerID == Input.GetTouch(i).fingerId)
                     cameraLeftFingerID = 9;
                 else if (cameraUpFingerID     == Input.GetTouch(i).fingerId)
                     cameraUpFingerID = 9;
                 else if (cameraDownFingerID == Input.GetTouch(i).fingerId)
                     cameraDownFingerID = 9;
                 else if (Input.GetTouch(i).fingerId == joystickFingerID)
                 {
                     joystickFingerID                                    = 9;
                     controllerUp                                         = false;
                     playerObject.GetComponent(playerScript).moveSpeed     = 0;
                     Destroy (JoystickObject);
                 }
                 else if (Input.GetTouch(i).fingerId == button2FingerID)
                 {
                     button2FingerID    = 9;
                     playerObject.GetComponent(playerScript).ButtonReleased(2);
                 }
                 else if (Input.GetTouch(i).fingerId == attackFingerID)
                 {
                     attackFingerID    = 9;
                     playerObject.GetComponent(playerScript).ButtonReleased(1);
                 }
                 else if (Input.GetTouch(i).fingerId == button3FingerID)
                 {
                     button3FingerID    = 9;
                     playerObject.GetComponent(playerScript).ButtonReleased(3);
                 }
                 else if (Input.GetTouch(i).fingerId == button4FingerID)
                 {
                     button4FingerID    = 9;
                     playerObject.GetComponent(playerScript).ButtonReleased(4);
                 }
                 else if (Input.GetTouch(i).fingerId == button5FingerID)
                 {
                     button5FingerID    = 9;
                     playerObject.GetComponent(playerScript).ButtonReleased(5);
                 }
             }
         }
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

21 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

Related Questions

Need Clarification on some Touch Struct Variables 1 Answer

¿Unity messing up fingerIDs? [Android] 1 Answer

Asynchronous Multi-Touch help - keeping track of touches and corresponding gameObjects (Android) 1 Answer

multiTouch problem when fingers close together (Bug?) 1 Answer

iPhone Multitouch Problem 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