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 VS · Apr 16, 2013 at 09:19 AM · cameraworldtoscreenpointperspective camera

How to reposition camera so that given plane point is in given screen position?

I have a x*z plane (at 0,0,0) and a camera pointing at it, in 60 degrees (and FoW of 60), at changing distance from the plane. Camera can move around, but its angle and relative position to screen (except for y/z according to distance) is static; so, if it now points to world point (0,0,0) and I want it to point to (2,0,2), I simply translate it by (2,0,2)

The problem: I need a function that takes a world coordinate "A" (x,0,z) and viewport position "V" (vx,vz) and returns coordinate where the camera needs to be moved so that after the camera translate, world coordinate "A" is in viewport position "V". If "V" is (0.5,05), this is like normal camera targeting operation, but because of the 3D projection, translation from screen position (0.5,0.1) to (0.5,0.3) is different camera move than from (0.5,0.7) to (0.5,0.9) and so on.

Apparently this is some basic mathematic formula but the details fail me - seems like a common problem (any draggable map in perspective camera) so there must be some (semi-)ready solution in Unity..?

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 robertbu · Apr 17, 2013 at 02:00 PM 0
Share

A draggable map in perspective does not have to use the calculation you are asking for. Rather than the solution you are looking for, can you describe the problem you are trying to solve?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Apr 17, 2013 at 02:51 PM

I'm not sure of the problem you are trying to solve, but in general I'd use raycast and perhaps Unity's mathematical Plane class. So given a viewport coordinagte, I can construct a ray using Camera.ViewportToRay(). If my surface has a collider, I can use Physics.Raycast() to cast into the scene. If I don't have a collider, I'd use a mathematical plane at the position of the surface and use the Plane.Raycast() to get the point. Given that you are at a constant 'Y' value, you then can compare the world position of the hit against the position you want at that position. This will give you the delta to move the camera.

You can also play this "game" in reverse if need be. You could construct a plane parallel to the surface that passes through the 'Y' value of the camera. You can then raycast from any point on the surface to this plane.

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

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

WorldToViewportPoint and WorldToScreenPoint give wrong positions when VR is enabled 1 Answer

WorldToScreenPoint, wrapping around when outside screen. 1 Answer

How can I accurately convert a Game Object's position to a sub Canvas/Rect screen position? 0 Answers

Calculation behind camera.WorldToScreenPoint 2 Answers

Adjusting returned WorldToScreenPoint for perspective angled camera 4 Answers


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