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 darthbator · Dec 14, 2012 at 12:01 AM · touchtouchscreentouchcountgettouch

Transitioning from different number of touches causes behavior overlap

Hey all! So I have a functionally basic model of moving my dudes around my environment. However 2 of my control input methods are not playing nicely!

My basic control setup is that pinching and pulling the screen with 2 touches will zoom the camera and touching a valid location on the screen with 1 will move the character. This all works correctly. The issue is that often when putting down or lifting up 2 fingers their strikes are often milliseconds apart causing the movement behavior to fire at an undesired location. I'm pretty sure the problem lies in how I am gating the behaviors (currently using Input.touchCount singularly) but I can't really think of another way that doesn't feel extremely complicated. Here are both pieces of code.

 void Update () {
         if (Input.touchCount == 1 && Input.GetTouch(1).phase != TouchPhase.Ended) {
             Touch touch = Input.GetTouch(0);
             if (touch.phase == TouchPhase.Began) {
                 touchMark = Time.time;
                 if (interactionRay(touch.position)) {
                     switch (hit.collider.gameObject.layer) {
                     case (int)Indexes.Layers.playerActor:
                         selectedActor = hit.collider.gameObject.transform;
                         StartCoroutine(myCameraMan.panToTarget(selectedActor, 1f, true));
                         break;
                     default:
                         if (touchDuration > touchDurationGate) actorMotors[selectedActor.gameObject.name].moveToPoint(hit.point);
                         break;
                     }
                 }
             }    
             if (touchMark == 0) touchMark = Time.time;
             touchDuration = Time.time - touchMark;
             if (interactionRay(touch.position) && touchDuration > touchDurationGate && (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary)) {
                 actorMotors[selectedActor.gameObject.name].moveToPoint(hit.point);
             }
             if (touch.phase == TouchPhase.Ended) {
                 touchDuration = 0f;
                 touchMark = 0f;
             }
             touchesDebug.text = touch.phase.ToString();
         } else {
             touchesDebug.text = "none";
         }
         if (selectedActor != null) {
             targetDebug.text = selectedActor.gameObject.name;
         }
         //Debug.Log(touchDuration.ToString() + "mark" + touchMark.ToString());
     }

And here is the camera code for 2 touches (living in another script).

 //Deal with pinch/pull zoom @2 touches
         if (Input.touchCount == 2 && !cameraMoving) {
             Touch fingerOne = Input.GetTouch(0);
             Touch fingerTwo = Input.GetTouch(1);
             float touchDistance = Vector2.Distance(fingerOne.position, fingerTwo.position);
             if (fingerOne.phase == TouchPhase.Moved || fingerTwo.phase == TouchPhase.Moved) {
                 float deltaTouchDistance = Vector2.Distance(fingerOne.position - fingerOne.deltaPosition, fingerTwo.position - fingerTwo.deltaPosition);
                 float newFoV = Mathf.Clamp(mainCam.orthographicSize + Mathf.Clamp(deltaTouchDistance - touchDistance, zoomClamp  * -1f, zoomClamp), camSizeClamp[0], camSizeClamp[1]);
                 mainCam.orthographicSize = newFoV;
             }
             if (fingerOne.phase == TouchPhase.Ended || fingerTwo.phase == TouchPhase.Ended) {
                 if (mainCam.orthographicSize < camSizeClamp[0] + bounceOffset) StartCoroutine(zoomCamera(camSizeClamp[0] + bounceOffset, 2));
                 if (mainCam.orthographicSize > camSizeClamp[1] - bounceOffset) StartCoroutine(zoomCamera(camSizeClamp[1] - bounceOffset, 2));
             }
         }

You can see in the code pasted first moving the character I setup a timer to try and gate the touch. The lowest effective thresh hold that causes the behaviors to work as I want is around .25f which makes moving characters feel really unresponsive and bad...

Any help is of course appreciated!

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

9 People are following this question.

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

Related Questions

check touch position 2 Answers

Please help. Attempting touch controls but I cant figure out what I'm doing wrong 3 Answers

Working with screen's touch limit 0 Answers

Unity Touch Help! 0 Answers

Android Screen Unresponsive to Touch After Many Activity Changes 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