Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 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 Sungold · Jul 09, 2016 at 09:21 PM · cameravisibilitycalculateplanesfrustum

CalculateFrustumPlanes not working

I tried the code on the Unity Scripting Reference to see how CalculateFrustumPlanes() works, yet it gave me these really weird planes that were not representative of the view frustum at all!

What's going on here?

http://docs.unity3d.com/ScriptReference/GeometryUtility.CalculateFrustumPlanes.html alt text

calculate-frustum-planes.png (224.9 kB)
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 Sungold · Jul 09, 2016 at 06:59 PM 0
Share

Do I need to add the position of the camera as offset to each of the planes' transforms?

1 Reply

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

Answer by Bunny83 · Jul 09, 2016 at 09:47 PM

They do work, but you interpreted the result wrong. The returned planes are infinite mathematical planes, not polygons. The example in the docs is actually misleading. Drawing a quad mesh for each plane makes no sense this way. There have been a lot questions about that topic. See this question for how to create a mesh that represents the camera frustum.

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 Sungold · Jul 10, 2016 at 12:30 AM 0
Share

Wow, thank you! It appears you did a lot of work on this topic. I actually was able to get the results I needed by just making each plane a child of the camera before calculating their rotation and position. In this way, I was able to get 6 quads that represented the frustum of the camera, and would rotate and translate with the camera (because they were childed). However, when I tried to use GeometryUtility.TestPlanesAABB() to tell if a particular collider was within the bounds of the planes, it would always return null. Is this because of what you are talking about?

         cam = Camera.main;
         planes = GeometryUtility.CalculateFrustumPlanes(cam);
 
 
         int k = 0;
         while (k < planes.Length)
         {
             GameObject p = GameObject.CreatePrimitive(PrimitiveType.Plane);
             p.name = "Plane " + k.ToString();
             p.transform.parent = cam.gameObject.transform;
             p.transform.position = (-planes[k].normal * planes[k].distance);
             p.transform.rotation = Quaternion.FromToRotation(Vector3.up, planes[k].normal);
 
             k++;
         }
avatar image Bunny83 Sungold · Jul 10, 2016 at 01:30 AM 1
Share

I just retested TestPlanesAABB and it works like expected. As soon as the AABB of a collider enters the viewing frustum TestPlanesAABB returns true, otherwise it returns false.

Your original question doesn't even mention TestPlanesAABB and seems to be more about visualizing the view frustum. Your original question is a hypothesis that states CalculateFrustumPlanes doesn't work. At no point you state what you actually want to do. When you ask a question it should be based on the problem you want to solve and not about speculations what might be wrong because the answer to such question is usually either "yes" or "no".

The planes returned by CalculateFrustumPlanes are oriented in worldspace. So the plane normal is a world space direction and the distance is the distance of the plane from the world origin.

Do you have any actual code you're using that doesn't work? If so you might ask a seperate question, stating what you actually want to do, what doesn't work and what you would have expected.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I trigger the visibility of an object through OnBecame(In)visible? 0 Answers

Which plane is which with CalculateFrustumPlanes 3 Answers

How to change camera visibility after certain distance? 0 Answers

Why is part of object outside camera frustum visible? 1 Answer

Can't see a flare from above? 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