Get Tiles In Players Field Of View

I’m creating a tile-based game with chunks, I’ve implemented a player field of view (FOV) using attachments and raycasts, which dynamically adjust the visible area.

Here’s an example of how it looks:

Now, I need a way to determine which tiles are within the player’s field of view:
From this:


To this:

also knowing which tiles are more visible and which are less visible, as represented in the image by different shades of blue.

How could I do that?

1 Like

Hmm, you could try shooting raycast out of the player’s head to the center of each tile to see if it’s obstructed along the way.

I would use CollectionService and WorldToScreenPoint

local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")

local Camera = Workspace.CurrentCamera
local Tiles = CollectionService:GetTagged("Tile")

RunService.RenderStepped:Connect(function()
   for _,Tile in Tiles do
     local _,OnScreen = Camera:WorldToScreenPoint(Tile.Position)
     if OnScreen then
        print(Tile.Name,"On Screen")
     end
   end
end)

Note that you could do alot to further optimize this, and it doesnt account for tiles created during runtime (you’d want to implement this for slow load times / issues with streaming enabled)