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 Manco Capac · Jul 03, 2014 at 01:34 PM · inputtouchtouchphase

Get object hovered over by touch

How can i get the object in 3D space touched, but not necessarily touch ended over. If the touch input starts at point A and ends at point D, and passes over points B and C, i want to get the point where the touch is held. In this case it will be point B and then point C. The touch will not necessarily be stationary/moving. It can be either. I want the effect of a slider, where the slider thumb will move to to object the over which the finger is held/moved.

I hope i could explain what i need.

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 HarshadK · Jul 03, 2014 at 01:38 PM 0
Share

I think I'm confused, could you provide a diagramatic explanation or something to make it more clear?

Paint works, too. :D

avatar image Manco Capac · Jul 03, 2014 at 04:47 PM 0
Share

I wonder why i didnt get an email notification. anyway:

This is the script im using :

 for (var touch : Touch in Input.touches) {
     if(touch.phase == TouchPhase.Ended){
 
         if (Input.touchCount == 1) {
             var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
             var hit : RaycastHit;
             if (Physics.Raycast (ray, hit)){
                 if(hit.collider.transform.parent.gameObject.name == "Sensitivity"){
                     sensitivity = parseFloat(hit.collider.transform.name);
                     GameObject.Find("Sensitivity$$anonymous$$nob").transform.localPosition.x = 2.175 - sensitivity * 0.375;
                 }
            }
       }
  }

}

alt text

What is happening now is that the Thumb(the radioactive icon) is just moving to the collider on which the touch input ends. i want it to be on the collider touched while sliding. (like the android volume slider)

screenshot (218).png (33.2 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by supernat · Jul 03, 2014 at 05:12 PM

I'm thinking out loud here, but you probably want to do this in two steps. First, find out all objects that lie within the plane from point A to point B, where point A is the left side of the slider here and point B is the right side. This could be done by creating a cone with its apex at the camera and its diameter the length of the slider, and its direction vector from the camera to the center point of the slider. Then you can test each collider in the scene (I would use layers additionally to limit the number of tests) as lying within that cone (simple dot product test). If your architecture makes it possible that other objects/colliders would fall within the cone above or below these colliders, then you would need to work with planes instead.

In step two, find out which object the current touch position is closest to by checking the distance between finger position and all object positions and keeping a reference to the object with the smallest distance. I would probably do all of those tests in screen space to make it easier. When your finger is between two colliders, the thumb will probably jump back and forth rapidly, so you'll also want some hysteresis in there.

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 Manco Capac · Jul 03, 2014 at 05:23 PM 0
Share

Thanks a lot. I think my case is much simpler, so i can do this more easily. I just figured it out :) Thanks

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

22 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

Related Questions

Unity 2D Touch Controll via on screen button for Mobile 0 Answers

Touch inputs Angry-bird style 0 Answers

How to detect whether a particular touch has ended? 1 Answer

Input.GetAxis("Vertical") on touch devices. 2 Answers

Help with a button 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