Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by stblue · May 16, 2014 at 01:22 PM · camerascreentoworldpoint

Camera.main.ScreenToWorldPoint return camera position

Iam trying to get world co-ordinate from my screen touch position, all i have is a cube in my scene and i am attaching a script to it which will return world co-ordinate, here is the update function from script.

 function Update () {
 for (var touch:Touch in Input.touches) 
     {
     Debug.Log(touch.position +" "+Camera.main.ScreenToWorldPoint(Vector3(touch.position.x,touch.position.y,0f)));
     }
 }

and here is the kind of output iam getting

 (135.9, 235.5) (0.0, 18.0, 0.0)
 UnityEngine.Debug:Log(Object)
 TestIos:Update() (at Assets/Scripts/TestIos.js:26)
 (154.1, 226.7) (0.0, 18.0, 0.0)
 UnityEngine.Debug:Log(Object)
 TestIos:Update() (at Assets/Scripts/TestIos.js:26)
 (162.6, 223.1) (0.0, 18.0, 0.0)
 UnityEngine.Debug:Log(Object)
 TestIos:Update() (at Assets/Scripts/TestIos.js:26)

what is the issue or what i am doing wrong, ScreenToWorldPoint return (0,18,0) which is my main camera co-ordinate, please help me with this issue.

Comment
Add comment · Show 1
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 CodeElemental · May 16, 2014 at 01:40 PM 0
Share

When you use ScreenToWorldPoint() the third coordinate is the actual distance from the camera ( which in your case is 0) . Try increasing it to gain more "depth" into the world.

2 Replies

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

Answer by HarshadK · May 16, 2014 at 01:48 PM

Here's a question that discusses the same issue as yours: Camera Screen to world point returns cameras transform position

So basically the reason is that since you are providing 0 for the z there is no depth present.

So if you want to know the world position you have to provide z value for the depth at which you want the point from the world co-ordinate otherwise use raycasting.

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 dyllandry · Jun 06, 2018 at 06:11 PM 1
Share

Helpful tip: If you store the return value of Camera.main.WorldToScreenPoint() in a Vector3, despite the z value being irrelevant in screen positioning, the z value required to convert back accurately to world space using Camera.main.ScreenToWorldPoint() is preserved.

avatar image
1

Answer by chethanb · Nov 17, 2020 at 11:34 AM

Find the Y(up axis value) value of the camera and the plane in the world. Find the difference between them and use that as Z value in Camera.main.ScreenToWorldPoint(Vector3(touch.position.x,touch.position.y,Z)));

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

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

Healthbar follow with screenspace-camera canvas 0 Answers

Camera not being moved when dragged by mouse 0 Answers

Projecting Oblique Screen Coords to Straight World Coords 1 Answer

Camera ScreenToWorldPoint Instatiating 1 Answer

Wrong world point mouse position 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