• 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 Case23 · Jun 29, 2010 at 10:35 AM · camerafovfieldofview

Find out if GameObject is in Field of View

I try to calculate if a GameObject is in Field of View of my Camera.

Edit: Becouse if not i want to disable the MeshRenderer of the GameObject.

Is there a buld in function i didnt find till now? Right now im using this code snippet which looks to work right. But im not sure.

Vector3 cameraRelative = _camTransform.InverseTransformPoint(gO.transform.position); Vector3 screenPos = _cam.WorldToScreenPoint(gO.transform.position);

if (screenPos.x > 0 && screenPos.x < Screen.width && screenPos.y > 0 && screenPos.y < Screen.height && cameraRelative.z > 0) // The object is in front of the camera _inView = true; else // The object is behind the camera _inView = false;

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

2 Replies

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

Answer by Mike 3 · Jun 29, 2010 at 11:05 AM

You can just use this:

bool visible = renderer.isVisible
Comment
Add comment · Show 6 · 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 Case23 · Jun 29, 2010 at 11:39 AM 0
Share

Perfect! Thank you!

avatar image Case23 · Jun 29, 2010 at 12:08 PM 0
Share

I cheered to fast. I have a little problem. After i disable the rendere. I, not able to Enable it again, because after that renderer.isVisible is always false.

avatar image Mike 3 · Jun 29, 2010 at 12:10 PM 0
Share

Why do you need to disable the renderer if it's out of view again? it's not being rendered

avatar image Case23 · Jun 29, 2010 at 12:15 PM 0
Share

Ahhh! If the renderer is not vissible it will not be rendered at all? So i can use isVisible only for my calculations? I testet it and it look that it works in this way!

avatar image superme2012 · Jun 22, 2013 at 07:43 PM 0
Share

Nice

if(AI_$$anonymous$$an_$$anonymous$$esh.renderer.isVisible){ Debug.Log("I can see a you mr AI man!!"); }

Handy!

Show more comments
avatar image
0

Answer by spinaljack · Jun 29, 2010 at 10:41 AM

There's an option to stop animations if the object is not in view

http://unity3d.com/support/documentation/ScriptReference/Animation-animateOnlyIfVisible.html

Comment
Add comment · Show 1 · 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 Case23 · Jun 29, 2010 at 10:50 AM 0
Share

Sorry I sayd the wrong thing. I dont use the Animation Class from Unity, ins$$anonymous$$d i using the iTween library. Also i want to disable the $$anonymous$$eshRenderer on the GameObjects not in view.

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

1 Person is following this question.

avatar image

Related Questions

Negative results when converting HFOV to VFOV? 1 Answer

Automatically adjust cameras FOV to maintain a perfect 360 coverage with multiple cameras 0 Answers

Is there a way to set the horizontal field of view of a camera? 3 Answers

How to animate zooming in of the camera? 4 Answers

Change field of view over time 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