#Find all "cubes" that the camera can see

1 messages · Page 1 of 1 (latest)

fast crown
#

I'm trying to have the player camera grab a list of all interactables ("cubes") that it can see.
I have a vague idea of it being doable using groups or layers, but don't know how to implement it.

slender pulsar
#

2D or 3D?

fast crown
#

3D

slender pulsar
#

If you just need to occasionally grab a list of cubes, you can do it by using groups. get_tree().get_nodes_in_group("Group Name") gets you a list of all nodes in the group, and you can check whether they're on screen by comparing Camera3D.unproject_position to get_viewport().get_visible_rect(). If you need more precision, use get_aabb() on the cube meshes and unproject all 8 corners of the AABB.

#

If you need a constantly updating list of cubes, use VisibleOnScreenNotifier3Ds. They emit a signal when they come/go from view and you can check the initial state with is_on_screen().

#

I forgot to consider one thing. This doesn't take walls/obstacles into account. You may need to do some raycasting if you only want to detect cubes that aren't hidden behind other objects.