https://gyazo.com/d81b34c7f769e7ece7cdae271a327e53
When the player hits the boundary along the “y-axis”, raycasting along the “y-axis” works perfectly fine.
However, when the player hits the boundary along the “x-axis”, additional tiles are shown visible even though I only want all tiles within 5 tiles of the player to be shown.
ShowTile(self.Hex)
for _, Direction in pairs(self.DirectionTable) do
local FilterTiles = {self.Hex}
--local FilterTiles2 = {self.Hex}
--raycast along x tiles
for i=5, 1, -1 do
local RayResult = workspace:Raycast(self.HexOrigin, Direction, self.RayParams)
if RayResult then
Result = RayResult.Instance
if Result.Parent.Name == "Tile" then
table.insert(FilterTiles, Result)
self.RayParams.FilterDescendantsInstances = FilterTiles
ShowTile(Result)
end
end
-- Raycast along y tiles
for _, Direction2 in pairs(DirectionTable2) do
for i=5, 1, -1 do
local RayResult = workspace:Raycast(Result.Position, Direction2, self.RayParams)
if RayResult then
local Result = RayResult.Instance
if Result.Parent.Name == "Tile" then
table.insert(FilterTiles, Result)
self.RayParams.FilterDescendantsInstances = FilterTiles
ShowTile(Result)
end
end
end
end
end