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 Laph1n · Dec 11, 2014 at 05:24 PM · cameracoordinatesarea

How to get Camera's field of view boundaries coordinates?

Hello, guys! Have pretty simple question. You know that camera's field of view can be approached as rectangle. Please give me ANY idea how it is possible to get absolute coordinates of its "vertices"?

Maybe some info about my game goal would be useful for the answer. I need to restrict the area in which I will randomly spawn objects to the field of view of camera, that is, that no objects are spawned beyond camera.

Thanks in advance!

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 NoseKills · Dec 11, 2014 at 05:24 PM 0
Share

Orthographic or perspective camera ?

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by smoggach · Dec 11, 2014 at 05:35 PM

That's pretty tricky. My approach would be to start with the rectangle instead of trying to find it.

     float x = Vector3.Distance(Vector3.zero, Camera.main.transform.position);
     float y = height / 2f;
     float requiredFOV = Mathf.Atan(y / x) * Mathf.Rad2Deg;
     Camera.main.fieldOfView = requiredFOV * 2f;

this code looks at the height of your given rectangle and sets the camera's FOV to show only that rectangle. You could modify this formula to find the rectangle at a given distance but imho it's better adapt your camera to the rect than the rect to the camera.

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

Answer by Kaushik Banerjee · Sep 04, 2015 at 01:11 PM

Try this..

Camera.ViewportToWorldPoint

You can use lowerBound = Camera.main.ViewportToWorldPoint(new Vector3(0,0,0)); upperBound = Camera.main.ViewportToWorldPoint(new Vector3(1,1,0));

Hope this helps.

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

Answer by DiegoSLTS · Sep 04, 2015 at 02:48 PM

There's this post in Unity's manual that tells you how to get the frustum size at a certain distance of the camera: http://docs.unity3d.com/Manual/FrustumSizeAtDistance.html

You can take a random value betwen near and far planes, get the size of the frustum for that distance and then a random value for that width and height.

With those random values you should always be inside the frustum.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Measuring XYZ coordinates in Unity vs in real life. 1 Answer

Have a gameObject follow the mouse in sync. So that the mouse pointer is always over the object. Even as the camera is rotated. 2 Answers

I want the camera to follow just the X coordinate of the player. 1 Answer

Screen Space is non standard in Unity? 1 Answer

How to get current Camera coordinates in a script 2 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