In order to increase performance for my game, I want to only show tiles within a set distance from the player.
The problem is when the ray does hit its neighbouring tile, the tile doesn’t seem to be added to its
FilterDescendantsInstances, with only the first neighbouring tiles being shown.
function LoadTilesModule:LoadTiles()
for _, Direction in pairs(self.DirectionTable) do
for i=5, 0, -1 do -- Show all tiles within 5 tiles of the player
local RayResult = workspace:Raycast(self.HexOrigin, Direction, self.RayParams)
print(self.RayParams.FilterDescendantsInstances)
if RayResult then
local Result = RayResult.Instance
if Result.Parent.Name == "Tile" then
table.insert(self.RayParams.FilterDescendantsInstances, Result) -- Add new parts to ignore
ShowTile(Result)
end
end
end
end
end
self.DirectionTable
is a table consisting of vector3’s which are used to cast a ray in different directions.
Only the tile the player is standing on is being filtered out in print(self.RayParams.FilterDescendantsInstances)