A way to fetch all visible objects on camera

Is there a way to get all objects visible on a camera at a certain moment inside an array optimally? A less optimal approach is to use WorldToScreenPoint with all BasePart descendants of workspace but of course you worry about checking over many objects.

I only need to fetch objects visible by the camera and I could apply a range if needed (100 studs for example as a range)

I started with the thought of creating a large invisible part that covers the whole camera and goes in the entire view extending forward with a specific range then receiving whatever is touching that part with GetTouchingParts (or Region3 could work if I could define the region exactly as well) but I don’t know exactly how I’ll do this considering the camera’s left and right angles where a straightforward part won’t cover everything seen properly.

(ViewportSize would be useful for this case if needed for raycasts from screen to world.)

Basically, I am looking for how to carry out my thought experiment into code or the best approach to this method.

There’s not a particularly great way to do this as far as I am aware. The methods you listed could work but you’d have incredibly low fidelity with raycasts and probably pretty poor performance.

Imo, you’d probably be better to split the worldspace into chunks, finding which chunk the camera is in, and then determining whether those objs are visible from the perspective of the camera. If you require a larger draw distance, since you know the camera orientation + its position, you can iteratively step through all chunks in that direction relative to the initial chunk

1 Like

In my original thought experiment, raycasts are not used so I tried to use just Ray objects, ViewportSize, and was able to create a part that would cover relatively the whole screen but not the camera vision. (ViewportSize to get my part size by getting ray objects from the opposite corners with ViewportPointToRay then adding their origin and direction instead of raycasting)

Raycasts were just mentioned as a possibility if they were used but maybe they don’t have to be.

I will consider the chunks idea but considering if raycasts were not used, would there still be a possible approach?