- Home /
Sector scanning in Unity
Hi,
I'd like to ask you about good/best solution for solving a problem with sector scan as illustrated on picture: http://content.answcdn.com/main/content/img/McGrawHill/Aviation/f0570-03.gif
This is required for me to have all objects that are visible by camera to be for example marked. I'd like to have rectangle, e.g. rectangle target and mark all objects inside this target. In unity there is nothing like "SectorCast".
Do you have any idea for solution of this problem ?
Thanks.
Answer by robertbu · Aug 07, 2013 at 02:47 PM
To solve the problem you outline in your comment, you can use Viewport coordinates. Viewport coordinates go from (0,0) in the lower left to (1,1) in the upper right. You can convert point into world space using Camera.WorldToScreenPoint(). You would define your rectangle in terms of viewport coordinates and then test points to see if they are inside the rectangle. I'm not sure how strict you need your visibility test to be. If you are look to see if any part of an object is within the rectangle, you can test all the points on the Renderer.bounds.
Answer by ________ · Aug 07, 2013 at 01:43 PM
This may not help as I don't really know what your want to do but you could try:
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnBecameVisible.html and http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnBecameInvisible.html
It's sth like this but I'd like to catch object not in the whole screen that is visible by camera but only part of it (rectangle in the middle of screen). Example - imagine that you cover camera with glass with rectangle painted in the middle of the glass and you want filter objects that camera sees trough this rectangle.
Answer by TonyLi · Aug 07, 2013 at 02:34 PM
You could use Physics. Add colliders to your objects. Set up a collider that extends out from your camera. Use OnCollisionEnter/OnTriggerEnter and OnCollisionExit/OnTriggerExit to keep track of what objects are within the camera's collider.
That's very curious idea. I'm not sure if this is possible to create piramid-shape collider in Unity for this purpose but I'll try.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111713im_/https://answers.unity.com/themes/thub/images/avi.jpg)