I was working on A* path finding until I thought of a problem, i need to get the positions in tiles in a part.
So take the reference image as an example of a 5X5 part, so I want to get the positions of each red dot, but I can only figure out how to get the positions of the center and the 4 corners.
I tried making each block 1X1 but it’s not a great solution for my game I’m currently working on. Any recommendations on how should I code it to make it possible for me to get the positions of every red dots? Thanks?
If you have all the tiles as seperate parts you could do something like this:
Tiles = {}
for _, tile in pairs(game.Workspace.Tiles:GetChildren()) --Change the bit within the brackets to be where the tiles are
table.insert(Tiles, tile.Position)
end
Use for loops to iterate over every X, Y and Z coordinate. E.g.:
local TILE_SIZE = 1
function getTileCoordinatesInPart(part)
local coordinates = {}
-- local corner1 = Vector3.zero --Part center
-- - part.Size / 2 --To corner
-- + Vector3.one * 0.5 * TILE_SIZE --To tile center
local corner1 = -part.Size / 2 + Vector3.one * 0.5 * TILE_SIZE
local corner2 = part.Size / 2 - Vector3.one * 0.5 * TILE_SIZE
for x = corner1.X, corner2.X, TILE_SIZE do
for y = corner1.Y, corner2.Y, TILE_SIZE do
for z = corner1.Z, corner2.Z, TILE_SIZE do
local coordinate = Vector3.new(x, y, z)
table.insert(coordinates, part.CFrame:PointToWorldSpace(coordinate))
end
end
end
return coordinates
end