Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 binoculars88 · Nov 26, 2017 at 07:52 PM · distancescreentoworldpointvector3.distance

ScreenToWorldPoint and Vector3.Distance give different values

In my FPS, I have a gameObject which I place in the game world using ScreenToWorldPoint. The z-parameter for this function is 20. The docs state this z position is "in world units from the camera".

Next (without moving the camera/player), I calculate the distance between the camera and this object using Vector3.Distance. This distance appears to be greater than 20. It also appears to be dependent of the other parameters of ScreenToWorldPoint. On a FOV of 65, I mostly get values between 20 en 25. On a FOV of 130, I get values between 60 and 70.

What am I missing here? Is there a way to actually place the object 20 units from the camera, independent of the FOV?

Thanks in advance!

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
Best Answer

Answer by Bunny83 · Nov 26, 2017 at 08:09 PM

It is the distance from camera in "parallel space". So the resulting distance will lie in one frustum plane that is parallel to the screen and not on a spherical surface. Of course the euclidean distance between the camera origin and the resulting point will be larger the further out the point is from the screen center.


If you want to place an object on the spherical surface around the camera origin with a radius of 20 you just need to renormalize the relative vector after projection. However an easier solution would be to use ScreenPointToRay and use GetPoint with the desired distance.

Comment
Add comment · Show 2 · 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 Dray · Nov 27, 2017 at 12:08 AM 0
Share

This is right. Another explanation for the unexpected results is that (I'm guessing) ScreenToWorldPoint is internally really just multiplying the point on the screen with a screen-to-world matrix and both, the screen- aswell as the world-matrix do have a depth.

avatar image binoculars88 · Nov 29, 2017 at 02:05 PM 0
Share

Thanks! I tried ScreenPointToRay in combination with GetPoint, and it works now! Note: there's still a difference with the distance calculated using Vector3.Distance, but it's a $$anonymous$$or difference I can live with (values in 130 FOV are around 20.1, in 30 FOV around 20.03). I wonder why that is... any ideas?

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

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

Related Questions

Check how far and if the object is in view and do something. 0 Answers

Error with rotation and attacking, enemy Ai 2D 0 Answers

What am I doing wrong in my distance calculation? 0 Answers

how to Calculate A Car Travel Distance towards Target, 0 Answers

Get x and y Distance between two Vectors 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