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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by calefaccio · Aug 29, 2014 at 12:33 PM · objectdragmultitouch

1 finger object dragging ignoring the second one

I'm trying to make a ball draggable around the screen without the need to touch it when dragging. I mean if I tap an empty space and drag, the ball should move the samed "dragged" distance.

I've managed to make it work if I only use one finger. The problem is that when the user uses another finger the ball goes crazy.

The working code for "one finger" I'm using is: (where inicial means Initial)

     if(Input.GetMouseButton(0) && playing)
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, rayCastHit))
         {
             xfinal = rayCastHit.point.x;
             yfinal = rayCastHit.point.y; 
             if(!isJump){
             transform.position.x = transform.position.x + (xfinal - xinicial)*sensibility;    //OJJOOO falla aqui!!
             transform.position.y = transform.position.y + (yfinal - yinicial)*sensibility;
             }
             xinicial = xfinal;
             yinicial = yfinal;
             if(isJump) Debug.Log("is Jumping");
             isJump = false;
             if(!isJump) Debug.Log("Nojump");
         }
     }
     else{
         isJump = true;
         Debug.Log("is Jump = " + isJump.ToString());
      
     }

I undersand that when the second finger touches the screen this line generates the problem:

 transform.position.y = transform.position.y + (yfinal - yinicial);


Any suggestion how to manage the second finger ?

Comment
Add comment · Show 2
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 robertbu · Aug 29, 2014 at 01:30 PM 0
Share

There's no finger dragging code here, but one solution is to limit your processing to when there has only been a single finger during that touch 'session'. That is when the first finger goes down, you enable dragging. When a second finger goes down you disable dragging until there are no fingers touching again.

avatar image TRG96 · Aug 29, 2014 at 03:22 PM 0
Share

Where is the code for touchscreen control? You can use Input.GetTouch() to get the finger ID. Input.GetTouch(0) is the first finger that touched the screen, Input.GetTouch(1), if there are 2 fingers touching then 1 is the ID of the second finger and so on. You can use the ID t get the position and state of either finger

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

dragging out an object from mouse click? 1 Answer

How can I manipulate an object with the mouse? 1 Answer

Imported Object Transform ignored when dragged to Hierarchy since updating to 4.5 0 Answers

drag object ios 2 Answers

Android Object Drag With Touch Problem 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