• 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 The-Oddler · Jul 27, 2013 at 03:56 PM · cameraaspect

DrawFrustum not the same as camera

Hi,

I've been trying to draw a frustrum of a camera point. I've been using Gizmos.DrawFrustrum(...) yet for some reason it doesn't match the gizmo of the camera. I can't find what I'm doing wrong, so hopefully someone here knows.

Here's my code:

     Gizmos.matrix = Matrix4x4.TRS(
         Camera.main.transform.position,
         Camera.main.transform.rotation,
         Vector3.one);
     
     Gizmos.DrawFrustum(
         Vector3.zero,
         Camera.main.fieldOfView,
         Camera.main.farClipPlane,
         Camera.main.nearClipPlane,
         Camera.main.aspect );

And this is what it looks like: alt text

If I change the aspect ratio of the camera, the frustum does not change. For some reason the Camera.main.aspect is always 1.3333 and I don't have a clue why.

Any help would be appreciated!

Thanks

Comment
Add comment · Show 9
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 DavidDebnar · Jul 27, 2013 at 04:27 PM 0
Share

Are you sure your code isn't picking up the Scene View camera? Try to extend the Scene window and see if 1.333 changes.

avatar image The-Oddler · Jul 27, 2013 at 05:15 PM 0
Share

I'm sure. I tried changing the scene view. Also, my scene and game view are both docked in the same window ( http://i.imgur.com/wFAoYvU.png ), so changing one changes the other. But nope, that's not the problem. I did notice that when I use Camera.current, ins$$anonymous$$d of Camera.main, it does change the aspect, since then it uses the scene camera. Also, when I disable my main camera (the only one in the scene) I get a null error in my frustum drawing script, since then Camera.main doesn't exist anymore. So by that I'm pretty sure it's accessing the right camera.

avatar image tw1st3d · Jul 27, 2013 at 05:18 PM 0
Share

Are those the only variables that can be pulled from your camera? Seems like it might be missing something small that would cause a wider view.

avatar image DavidDebnar · Jul 27, 2013 at 06:06 PM 0
Share

Try to store the camera in a variable, so you don't get this error. Also, don't expect the gizmos to fully line up. I had this problem once too, when the gizmos didn't quite line up to the camera frustrum, and I solved it by calculating the frustrum manually via trigonometry.

avatar image cecarlsen · Mar 28, 2014 at 03:40 PM 0
Share

I'm trying to do the exact same thing and I get the exact same error.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by AtticusMarkane · Feb 04, 2015 at 08:33 AM

There are a couple of other threads that people have replied with solutions for drawing it yourself. It would just be nice if this was a silly gotcha that was easy to get around.

Here is a link to one such solution for the next guy that comes around: http://forum.unity3d.com/threads/drawfrustum-is-drawing-incorrectly.208081/

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

How to make camera position relative to a specific target. 1 Answer

Different Aspect ratios cuts off game 1 Answer

Game Resolution and Scaling Unity 2D 0 Answers

Set camera aspect ratio and position 1 Answer

RenderTexture, Camera.aspect and Camera.fieldOfView 0 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