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 junaum · Feb 22, 2012 at 04:04 PM · touchtouches

A different take on multiple touches

Hi there,

I'm trying to create a simple input system for a 2D platformer that basically takes the rightmost 2/3 of the screen for touch input/swipes, and the leftmost 1/3 part for a simple JoyPad that spawns where the user touch.

So, if the user touch the left part of the screen, I need to spawn the joystick, and keep it alive even if he slide his finger over the right part of the screen. On the other hand, I have to compute his right screen swipes, even when it exceeds the left area. I'm trying to achieve that in a way that the input system doesn't get confused with different inputs, and generate swipes with the joy touch, or vice-versa.

I did my best (which is not very much) and couldn't figure out a safe way to do this without bugs and glitches. The "Penelope" input solution didn't cut it as well (it threads the joy as a fixed gui element, and mine is dynamically spawned).

The relevante part of the code is my "GetTouchOutput" function, which runs on Update(), but there are functions used on the example below (not directly relevant, but I can post it if necessary). setTouchMotion just computes a formated touch output to be used by the game, and joyDraw / touchDraw are responsible for designing the gui elements on the fly. The touchZone is Rect(Screen.width - touchSize,0, Screen.width, Screen.height).

Any help will be most appreciated! Thanks in advance.

 function getTouchOutput () {
     
     var i : int = 0;
     var j : int = 0;
     
     var count : int = Input.touchCount;        
 
     if (count > 0) {
     
         while(i < count) {
                 
             if (!touchStartSet[i]) { 
             
                 touch[i]  = Input.GetTouch(i);
                 touchFinger[i] = touch[i].fingerId;            
             
                 touchStart[i] = touchCurrent[i] = touch[i].position;    
                 touchStartSet[i] = true;
                 
                 if (touchZone.Contains(touchStart[i])) touchPad[i] = true;
                 else touchPad[i] = false;                
             }
             
             else {
                 
                 j = touchFinger[i];                            
                 touch[j] = Input.GetTouch(i);
                 
                 if (touchPad[j]) touchDraw(touchPrevious[j], touchCurrent[j]);                    
                 else joyDraw(touch[j].position, touchStart[j]);
                     
                 touchPrevious[j] = touchCurrent[j];                                             
                 if (touch[j].position != touchPrevious[j]) touchCurrent[j] = touch[j].position;    
                 
                 touchOutput[j] = setTouchMotion(touchPrevious[j], touchCurrent[j]);    
                 
                 if (touch[j].phase == TouchPhase.Ended || touch[j].phase == TouchPhase.Canceled )
                     touchStartSet[j] = false;    
             }
             
             i++;            
         }
     }
 }
 
 function Update() {    
     getTouchOutput ();    
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Touch not working on guiTexture. 1 Answer

GameObject dropping and laging while dragging on Android 2 Answers

Not getting a response when a touch doesn't move with TKtouchkit 1 Answer

Two touches in same time? 0 Answers

Why can't I press both my touch controls at the same time? 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