Check wheter something is visible for the main camera?

Hey, I searched on google on how to do this so I tried various different codes,
Here are some that I remember:

Renderer.IsVisible
Renderer.OnBecameVisible

and I’m currently with:

		if(renderer.IsVisibleFrom(Camera.main))
		{
			print("You can see him");	
		}

(I also use a RendererExtension script so I can use “IsVisibleFrom”)

But once applied to an object, the “You can see him” is always spammed.
Anyone might happen to know how to check whether or not the maincamera can see a specific object?

I think, the reason somewhere in that RendererExtension and method IsVisibleFrom.

If you’re using the the RendererExtension from http://wiki.unity3d.com/index.php/IsVisibleFrom#C.23_-_RendererExtensions.cs than it works just fine for me.

You can easily test it in play mode when you move the object in the scene view behind the camera. Than the output immediately stops.

The method just just tests if the object is in the culling frustum of the camera (if the camera can see the object). It doesn’t check if the object is covered by other objetcs. Maybe this is what you want.

Oh, right! silly me!
The object is behind a wall and yet it sees me, I read something about layers in order to prevent this but I’m not sure, any ideas?

A long time ago I wrote a simple asset which determines wether a object is visible to the camera or not, using occluders to block the visibility, you can have a look into it, as far as I know there is a property in one of the components inside the asset which simply gives you the visibility state. Its worth a try:

http://www.dras.biz/download/Occluder/Occluder.unitypackage

Here a simple webplayer which demonstrates that it works by disabling the renderers of objects not visible to the camera:
http://www.dras.biz/download/Occluder/WebPlayer.html

Thanks Marrrk! but I get this message while trying to enter the website “Oops! Google Chrome could not find www.dras.biz”

Works at least for me and some hundred other people :wink: Try again, maybe there where some maintenance work done.

Crap :confused: no luck. Do you mind uploading it to mediafire or something?

Sure, try this: https://dl.dropboxusercontent.com/u/2446365/Occluder.unitypackage

Thanks! :slight_smile:
Now let’s see if I can fix this!

edit:
Crap…nothing seem to work :frowning:
I added the OcclusionCamera to my maincamera and Cccludable to the walls.

I think there is something missing, as far as I know the walls need to be Occluders and not Occludables, there should be two different components for this, it has been a long time since I created these.

When trying to add a Occulder to the wall I get this:

Is there something else I can do to fix this? besides using your scripts.

Add “Occludable” to the objects you want to use for your checks and “BoxOccluder” or “PlaneOccluder” to your walls.

http://gyazo.com/9d5b09961ab1fd806c8eedd57c5d1a6f Still nothing, this is how it looks like.
The object inside the red ring got the “Occludable” script on it.