• 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 ina · Oct 29, 2011 at 05:50 AM · touchlocalglobalcoordinate

Touch point to world coordinate and local coordinate

How do you convert a touch point to world coordinate and local coordinate?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mkovac · Mar 20, 2012 at 09:38 AM

Beware that 2D touch point when transformed to 3D scene becomes a ray rather than single point. This ray hits everything painted on the touched screen point. You will have to do a raycast to see what exactly was hit and where

Touch position can be translated to ray as follows:

 Ray ray = Camera.main.ScreenPointToRay( Input.touches[0].position );

This ray is in world space and if you want to know what it hits (i.e. what is touched on screen with finger), do a raycast. If something was hit, exact hit position in world space will be stored in hitInfo:

 RaycastHit hitInfo;
 if (Physics.Raycast( ray, out hitInfo ))
 {
     Vector3 worldSpaceHitPoint = hitInfo.point;
 }

If you want to know local position of hit on object which was hit by raycast, you will simply transform worldSpaceHitPoint into object's local space. The hit object is also stored in hitInfo:

Vector3 localSpaceHitPoint = hitInfo.transform.worldToLocalMatrix.MultiplyPoint( worldSpaceHitPoint );

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help with local and world translation.position 0 Answers

Local Velocity for Rigidbody? 1 Answer

AddRelativeForce isn't staying 'relative'. 1 Answer

Make everything use "world space" coordinates? 0 Answers

How do I return local normals? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges