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 ALAN! · Jan 26, 2013 at 09:22 AM · coordinatesraycasts

Converting iPhone touch to world coordinates

Hello! I know this is super simple stuff, but I've been digging for over an hour now and can't figure out how to turn screen touch coordinates into world coordinates. Specifically, I want to detect when the user taps a specific enemy so that enemy can then die, kinda like whack-a-mole. I know it involves RayCasts but I'm kind of having trouble comprehending what those are, and what all of its function parameters do. I've been staring at the Unity documentation for a while, pretty confused over here! Sorry this is question is so dumb but any help, guidance, advice would be super appreciated. Thanks <3 <3 <3

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 Fattie · Jan 26, 2013 at 10:46 AM 0
Share

WDIDI has given the answer. Also go to unityGE$$anonymous$$S.com for priceless articles on this. Also here is an outlandishly long discussion on the matter

http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html

avatar image ALAN! · Jan 28, 2013 at 02:17 AM 0
Share

hey don't be spam$$anonymous$$ your website dawg i don't see nothin about touch input on there!!

1 Reply

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

Answer by whydoidoit · Jan 26, 2013 at 09:31 AM

Ok so a Raycast is what you want. A raycast is a line drawn through the scene from some point, in some direction for some distance. Depending on which function you call that will either return the first thing that is hit, all of the things etc etc.

Your camera is a point in the scene (the view on the screen is what can be seen from that point with the current camera settings).

To make the direction of the line for touching it uses the point which is the camera and the point which represents the finger - those two points make a line which represents the direction from the camera through the scene. Fortunately the camera does the heavy lifting and can covert a screen position to a Ray for you.

So presuming you want to use your currently active main camera:

      RaycastHit hit;
      //Get the camera to make the ray
      var ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
      //Check if the ray hit something and return the info
      if(Physics.Raycast(ray,  out hit))
      {
           //Use hit.collider.gameObject to get the gameObject hit
           //Use hit.collider.GetComponent<Something>();
      }
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 ALAN! · Jan 27, 2013 at 07:42 AM 0
Share

Worked perfectly! Thanks!!alt text

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

11 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

Related Questions

Screen Space is non standard in Unity? 1 Answer

Single number coordinates display 1 Answer

Origin Placement Android Uity (Coordinates of Tuch positions) 0 Answers

Fix a GUI's position relative to a 3D object 1 Answer

2D gameobject array coordinates 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