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 Leroterr · Jul 19, 2014 at 07:10 AM · movementraycastvector3touchjoystick

Get the position of the first finger that touched the collider?

Is there a way I can get the touch position of only the finger that FIRST touched a certain collider?

For example, When I touch a collider, it will get the position of that touch. And when I touch the same collider again with a different finger AND I haven't let go of my first touch, it will just ignore the 2nd touch, and I should only have the position of the first initial touch.

EDIT: Only the first touch that hits the collider, not the actual first touch on the whole screen. Input.GetTouch(0) kind of gets the actual very first touch. So if the player hits the collider on the second touch, then it's (1), but it's the FIRST touch on that certain collider, even though in actuality, it's the second touch.

I'm not sure how to do this, I'm still kind of new to touches and stuff.

The current code I use returns the position of the first and second touch. So when I touch something, it will get that position, and when I touch it again, the position will change, as if it's combining both positions.

This is just an assumption though, I'm not sure if that's really the problem.

Here it is just in case: It's a joystick I use in moving my character. Whenever I just touch it once, it will do its work properly, But when I touch it again with another finger, my character speeds up, and there's no script that when I touch it twice, it will speed up. So I assumed it combining the position of the first and second, thus making my player move faster when I'm touching the same collider twice.

And yeah, it's not using anything that has to do with fingerIDs, because I'm still not sure how to use it in this situation.

 void Update () {
 
     //Handles touches
     for(int i = 0; i < Input.touchCount; i++)
 
             {
 
                 Touch touch = Input.GetTouch(i);
                 
                 Ray ray = GUICamera.ScreenPointToRay(Input.touches[i].position);
                 
                 touchPosition = Input.touches[i].position;
                 
                 if(Physics.Raycast(ray, out hit) && hit.collider.tag == "joystickTag")
 
                 {
                     
                     //the position of where the player touched
                     touchPosition = GUICamera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 72));      
 
                     //where you want to be (according to MoveTowards)
                     Vector3 desiredPosition = touchPosition;
                     
                     //your clamp is relative to this position
                     Vector3 origin = centerPos.position;
                     
                     //this vector points from 'origin' to 'desiredPosition'
                     Vector3 diff = desiredPosition - origin;
                     
                     //clamp the difference, then add it to the origin
                     transform.position = origin + Vector3.ClampMagnitude(diff, maxRange);
                     
                     tempDelta = new Vector3(transform.position.x - oPos.x, -72, transform.position.z - oPos.z).normalized;
                     
                     delta = Vector3.Lerp(delta, tempDelta, Time.deltaTime * 8.0F);
 
                 }
             
             }

         //This moves my player
         player.transform.Translate(((Vector3.forward * delta.z) * playerSpeed) * Time.deltaTime);
         player.transform.Translate(((Vector3.right * delta.x) * playerSpeed) * Time.deltaTime);
         
 }

Again though, I'm still not quite sure why it's going fast.

Thanks!

EDIT: Still need some help. :/

Comment
Add comment · Show 3
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 Leroterr · Jul 19, 2014 at 08:17 AM 0
Share

Sorry I forgot to mention that I had another button that the player needs to press as well. So what I actually wanted was the first touch THAT hits the collider, not the actual first touch on the entire screen. Forgot to mention, sorry.

avatar image Lo0NuhtiK · Jul 19, 2014 at 08:21 AM 1
Share

Alright lol ... was taking a stab in the dark with the first thing that came to $$anonymous$$d in case it might help xD

avatar image Leroterr · Jul 19, 2014 at 08:33 AM 0
Share

@tanoshimi I'm not sure how to do that in my situation though, I'm new to fingerIDs and Google and Unity Documentations doesn't help. I've actually tried and searched a lot about this on how to solve my problem, but none worked properly for me so I just asked myself.

1 Reply

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

Answer by tanoshimi · Jul 19, 2014 at 08:23 AM

It's hard to follow your scenario, but for any multitouch applications I tend to maintain an internal array/dict/list/whatever that records fingerid, object touched etc. and then process all game logic based on that rather directly trying to apply logic to Input.touches. You might want to give that a try.

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

23 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 avatar image avatar image

Related Questions

Move an object to Input.Touch location 0 Answers

Issues with Bullet Ricochet 1 Answer

Touch buttons for step movememt 3 Answers

Touch Crosshair problem. 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 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