I’ve got a classic Robloxian character with an R6 setup. I need to do an accurate check to figure out if a player can see them. If even a single pixel of the Robloxian shows up on the player’s screen, it should count as visible. I tried using local hitboxScreenPos, hitboxIsScreen = workspace.CurrentCamera:WorldToViewportPoint(hitboxPos)
for a specific point, but that only checks one position—what about the whole model? I’m all ears for ideas!
Use Camera:WorldToViewportPoint
on the models sample points and for those that project on screen, cast a ray from the camera to each point, if any ray first hits the model, it’s visible.
You’re asking for something impossible, at least on roblox. If you wanted to literally know if a singular pixel shows up you would need to make a raycast for each individual coordinate on the model which would be incredibly taxing even for the most powerful of computers. The recommended compromise is to just check if the coordinates in each corner of the model’s bounding box, along with one in the middle of each edge and one in the middle of the model itself, are visible.
Off roblox, you might be able to do it with code written to the gpu
This isn’t about labeling every single atom. I’d like to know if there’s a built-in method in the engine. Does one exist or not?
That is not what your post asked, but regardless the answer is no.
Roblox doesn’t expose GPU occlusion queries or depth buffer readback, so true per pixel visibility checks aren’t possible and casting a ray for every screen pixel would require thousands of raycasts per frame which is far too heavy in Luau, I agree. Although the practical workaround is to sample a handful of bounding box corners, edge midpoints and the center and raycast those instead
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.