NOTE: This is an offshoot from a previous topic about pathfinding. I decided to make a new topic for this specific issue because it’s very removed from the original discussion in the original topic.
I have a function generateMapGrid()
, posted below:
local function generateMapGrid()
local cframe, size = workspace:GetBoundingBox()
local cellsX, cellsY, cellsZ = math.ceil(size.X / OCTREE_SIZE), math.ceil(size.Y / OCTREE_SIZE), math.ceil(size.Z / OCTREE_SIZE)
local cellBounds, origin = OCTREE_SIZE * Vector3.new(cellsX, cellsY, cellsZ), cframe.Position
for x = 1, cellsX do
for y = 1, cellsY do
for z = 1, cellsZ do
local position = origin + Vector3.new(x, y, z) * OCTREE_SIZE - cellBounds * 0.5 - Vector3.one * OCTREE_SIZE * 0.5
table.insert(roots, position)
debugRootNode(position)
end
end
end
end
The function is intended to encompass the entire map in as few 512x512x512 blocks as necessary to encompass it fully. The larger purpose is to space out the root nodes for an octree across a massive map so it can automatically generate a rough collision map for pathfinding. On two different maps I’ve tried this on, though, I’ve run into the same problem; the function will only encompass specific parts of the terrain and leave out the rest of it, as demonstrated below:
Notice in the bottom left corner how the massive chunk of terrain on the map is not covered with the green, translucent blocks (root notes). The image above has no BaseParts in the scan area. When I add BaseParts, it will include those, but not the extra terrain:
The two houses floating off to the side of the original chunk of terrain are dragging the coverage out to meet them, but not to the terrain off to the top right of the image. Here’s another image:
Hard to see, but there’s a house on the second chunk of terrain that the function is going out to meet, yet it isn’t encompassing the rest of the terrain surrounding it. Very frustrating.
I’ve narrowed down the problem to the :GetBoundingBox()
function; it seems to think the latter terrain is not a part of the workspace’s physical makeup even though it was created in the same way as the terrain that is being captured in the bounding box. I have no idea what’s causing this and I don’t get any error messages or other indicators that something is failing except for print()
messages returning values for the size of the bounding box that are obviously wrong.
Below I’ve included the place file for you to play around with. Hopefully you can get a better idea of what the problem is:
octree-spacing.rbxl (4.0 MB)
I’ll try to answer any other questions as well.