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 GigaRoid · Jan 05, 2014 at 06:09 AM · cameraraycastrendererrenderer.enabled

Check if a camera is looking at an invisible object

I know how to check if the renderer is visible, but I want to know if a camera is looking at an object WITHOUT a renderer enabled. I don't want an object to enable rendering when a camera is looking in its direction. But when I use

if (boolName && !renderer.isVisible) { renderer.enabled = true; }

it renders anyway because renderer.enabled is false when that code is executed. This can be achieved by complex raycasting, but I don't know how to do that and I'd rather not add 50 extra lines of code. Thanks.

Comment
Add comment · Show 4
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 Benproductions1 · Jan 05, 2014 at 06:48 AM 0
Share

"This can be achieved by comlex raycasting", isVisible doesn't do raycasting, it simply checks whether the object is in the viewport volume. What do you want to achieve with this? There might be a better solution to your problem (such as raycasting)

avatar image GigaRoid · Jan 05, 2014 at 08:26 PM 0
Share

isVisible doesn't work when the renderer's disabled, right? STEP 1: The monster object takes a moment to disappear when the player looks at him (timer -> renderer.enabled = false;). STEP 2: The monster waits a few moments before reappearing (timer2 -> renderer.enabled = true;).

I don't want STEP 2 to happen if the monster would suddenly appear in the viewport. I would like to know how to achieve this.

avatar image Benproductions1 · Jan 06, 2014 at 03:52 AM 0
Share

I would use WorldToScreenPoint and check if it's in the bounds of the camera...

avatar image GigaRoid · Jan 06, 2014 at 09:45 PM 0
Share

I'm a noob. What variables do I use to do that?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Benproductions1 · Jan 06, 2014 at 11:57 PM

Hello,

To check whether a point can be seen by a camera you can check whether that point, transformed using WorldToScreenPoint has a x value between the range of 0 and the screen width (`Screen.width`), a y value in the range 0 to the screen height and a positive z value.

Hope this helps,
Benproductions1

PS: If you don't know how to code that, I suggest you learn coding before you try something like this ;)

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 GigaRoid · Jan 08, 2014 at 08:53 PM 0
Share

Thanks. I do know how to code that. I learn best by doing.

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

19 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

Related Questions

Camera raycast and rotated collider 0 Answers

Make the terrain ignore Raycast if in between Camera and Player? 1 Answer

Raycast Object Selection 3 Answers

Help with Raycast on Render Texture 0 Answers

Fire bullet to mouse position in 3d space 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