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 Steveosaurous · Jun 13, 2012 at 09:11 AM · androidinputtouchraymulti

Android Multi-Touch Issue

So I've been working with Unity Android for the past few weeks and have been struggling with one problem over and over and over again. I've gone through the documentation and even browsed through the Penelope scripts but I can't find a solution to this problem.

I'm working on the Acer Iconia A200 and testing with a basic unity script:

     for(MoveFinger = 0; MoveFinger < Input.touchCount; ++MoveFinger){            
         if (Input.GetTouch(MoveFinger).phase == TouchPhase.Began){ //USE WHEN PORTING TO ANDROID


            if (Physics.Raycast (moveray, FingerHit, 200, MoveLayer) && Spinning == false) {
                    if(FingerHit.collider.gameObject.tag == "ReturnNull"){
                    }
                    if(FingerHit.collider.gameObject.tag == "MoveLayer"){
                     StartClickTimer = true;
                     Debug.DrawLine(moveray.origin, FingerHit.point);
                     MoveTarget.position = FingerHit.point;
                 }
              }           
             }
  }

So the issue is this: it works perfectly when one finger is on the screen. When two fingers are on the screen it can't differentiate between the old finger and the new finger and so it averages the distance between the two. Additionally, it occasionally can't tell when a finger has been lifted from the screen and will read one finger as two.

What is a good workaround to this? The penelope script referenced a concept called "latching". How can I implement this?

Thanks in advance.

EDITED TO ADD NEWER/LONGER VERSION OF THE CODE

function Update(){

 var MoveLayer = 1 << 8;
 
 //Knowing the LerpDistance ensures constant Lerp Speed
 var moveray = Camera.main.ScreenPointToRay (Input.GetTouch(MoveFinger).position); 
 var ClickRay = Camera.main.ScreenPointToRay (Input.GetTouch(MoveFinger).position); 
 var FingerHit : RaycastHit;
 var ClickHit : RaycastHit;
 var LerpDistance = Vector3.Distance(PlayerShip.transform.position, MoveTarget.position);
 
 if(IsRotating == false){
     RotateTarget.localEulerAngles = Vector3(0,0, PlayerShip.transform.position.x * 2);
 }
 IsRotating = false;
 MoveTarget.position.x = Mathf.Clamp (MoveTarget.transform.position.x, -12, 12);
 MoveTarget.position.y = Mathf.Clamp (MoveTarget.transform.position.y, -6, 6);
 
 // After 10 seconds of damage has passed, start restoring the shield
 DamageTimer += 1 * Time.deltaTime;
 if (DamageTimer >= 10){
     RestoreShield();
 }
 
 
 ///If we're single clicking move at normal speed to the position
 if(DoubleClicked == false && Spinning == false){
 PlayerShip.transform.position.x = Mathf.Lerp(PlayerShip.transform.position.x, MoveTarget.position.x, Time.deltaTime / LerpDistance * ShipSpeed);
 PlayerShip.transform.position.y = Mathf.Lerp(PlayerShip.transform.position.y, MoveTarget.position.y, Time.deltaTime / LerpDistance * ShipSpeed);
         PlayerShip.transform.rotation = Quaternion.Lerp(PlayerShip.transform.rotation, RotateTarget.rotation, Time.deltaTime * ShipSpeed/2);
 }
 
 
 
 
         
         for(MoveFinger = 0; MoveFinger < Input.touchCount; ++MoveFinger){            
             if (Input.GetTouch(MoveFinger).phase == TouchPhase.Began){ //USE WHEN PORTING TO ANDROID
             FirstFingerID = Input.GetTouch(MoveFinger);
             MoveFinger = FirstFingerID.fingerId;
             print(FirstFingerID.fingerId);
                if (Physics.Raycast (moveray, FingerHit, 200, MoveLayer) && Spinning == false) {
               
                        if(FingerHit.collider.gameObject.tag == "ReturnNull"){
                        }
                        if(FingerHit.collider.gameObject.tag == "MoveLayer" && FirstFingerID.fingerId == 0){
                         StartClickTimer = true;
                         Debug.DrawLine(moveray.origin, FingerHit.point);
                         MoveTarget.position = FingerHit.point;
                     }
                     if(FirstFingerID.fingerId == 1){
                     print("I suck");
                     }
                  }           
                 }
            }
                 

}

The script basically moves a target named "MoveTarget" to a place in the world, designated by the player's finger touching the screen. Then the script Lerps the Ship model towards that target. Simple, but broken

Comment
Add comment · Show 22
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 whydoidoit · Jun 13, 2012 at 09:22 AM 0
Share

I don't see move ray defined there, what is it?

avatar image Steveosaurous · Jun 13, 2012 at 09:34 AM 0
Share

//var moveray = Camera.main.ScreenPointToRay (Input.GetTouch($$anonymous$$oveFinger).position);

avatar image hirenkacha · Jun 13, 2012 at 09:35 AM 0
Share

get a finger Id and use that in if condition.

avatar image Steveosaurous · Jun 13, 2012 at 09:37 AM 0
Share

how do I do that?

avatar image whydoidoit · Jun 13, 2012 at 09:40 AM 0
Share

Are we missing some code, because the current example looks like it only handles the Began event?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · Jun 13, 2012 at 08:01 PM

Ok so firstly you need to move the moveRay and ClickRay construction inside the for loop where MoveFinger is being updated.

I'm guessing it's just taking the wrong finger position and you will need to create a new ray for each finger, inside that loop.

Comment
Add comment · Show 1 · Share
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 Steveosaurous · Jun 13, 2012 at 08:13 PM 0
Share

Yep, that did it lol. Thanks so much for your help and your patience, $$anonymous$$ike

avatar image
0

Answer by Steveosaurous · Jun 13, 2012 at 11:04 PM

Okay, so I'm using Unity remote now for my debugging. I've been tracking my finger id's and they seem to be working properly. When I put one finger on the screen, the number is 0, a second finger is 1, 2, 3 and so on.

Now, how would I use fingerId to continuously track the same one finger? I'm just unsure how to implement the code still.

Comment
Add comment · Share
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

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

6 People are following this question.

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

Related Questions

Please confirm: Galaxy Stylus not readable directly in Unity 1 Answer

How to differentiate touches on mobile devices 1 Answer

Bug? Need to wait about 10 seconds to get back to normal 1 Answer

Joypad help 0 Answers

Taking Input from Android phones 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