# Unity - Renderer "raycasts" from top down?

I'm trying to have objects in a game be selectable only from a top down orthographic camera view. I think having physics colliders might be overkill for that - especially because this only needs to be in 2D and not 3D. Is there another method that might be better, such as something like a renderer "raycasts", but perhaps even more performant as it is just from the orthographic 2D top down view

If you build your "top down" view on the XY plane, you can use 2D colliders and Physics2D.OverlapPoint.

This is about as efficient as you will get. A 2D collider is using exactly the same math you'd need to write in your C# code to test for a hit anyway. And if you're using Kinematic bodies on a physics layer that doesn't interact with anything, they won't burn any cycles on unneeded collision detection and resolution.

• is there a way to automatically create 2D colliders from the top down for 3D meshes?
– ina
Dec 18 '20 at 1:16
• You could write a script to do it reasonably easily. Project all the triangles and make a polygon collider out of their perimeter. Dec 18 '20 at 1:19
• Or you could use GetComponent<Renderer>().bounds which gets you the bounding box of the object as its used for culling calculations and create a BoxCollider2D out of it. Dec 18 '20 at 9:12

you can use quadtree algorithm to detect which object under the mouse position

you can use octree algorithm in 3d space

• Why would you do that when Unity already provides that for you? Dec 18 '20 at 9:10
• some people like inventing the sledgehammer even though it is now commodity that's basically free
– ina
Dec 18 '20 at 23:51
• Some times you dont need whole physics features with heavy calculations Dec 19 '20 at 22:14
• Im using ECS and i had to use this algorithm for nearby object detection Dec 19 '20 at 22:15