Custom Navmesh system for some reason skipping nodes

I’m trying to program a A* pathfinding algortihm, but to do that i need to make my own navmesh.
For some reason after the grid is generated, when the nodes are checking if they’re inside or outside the Mesh, half of them get skipped, but only the ones that are outside of it

—video: Watch PATHFINDING TESTING - Roblox Studio 2026-08-07 15-46-42 | Streamable

—this is the script as of now

type Node = {
	Position: Vector3,
	GridCoordinates: Vector2,
	ConnectedNodes: {},
	Active: boolean,
	Visual: Model,
}

local NavMesh = game.Workspace.NavMesh
local NodeBase = game.ReplicatedStorage.TestingAssets.Node

local GRID_SIZE_X = 100
local GRID_SIZE_Y = 100
local GRID_DENSITY = 1

local AgentRadius = 1

local NodeList = {}

local NodeContructor = function(Pos: Vector3, coords: Vector2)
	local NewNode: Node = {}
	NewNode.GridCoordinates = coords
	NewNode.Position = Pos
	NewNode.Active = false
	return NewNode
end

local CreateGrid = function()
	local Center = NavMesh.PrimaryPart.Position
	local PassesLeft = math.round((GRID_SIZE_Y/GRID_DENSITY) + 2)
	local Xcoord = 0
	local Ycoord = 0
	for Passes = 0, (math.round((GRID_SIZE_X  / GRID_DENSITY) + 2) * math.round((GRID_SIZE_Y/GRID_DENSITY) + 2)), 1 do
		local NodePos = Center - Vector3.new(GRID_SIZE_X/2 - (GRID_DENSITY * Xcoord), 0, GRID_SIZE_Y/2 - (GRID_DENSITY * Ycoord))
		local coords = Vector2.new(Xcoord, Ycoord)
		local Node = NodeContructor(NodePos, coords)
		if PassesLeft == 0 then
			PassesLeft = math.round((GRID_SIZE_Y/GRID_DENSITY) + 2)
			Xcoord = Xcoord + 1
			Ycoord = 0
			task.wait()
		end
		Ycoord = Ycoord + 1
		PassesLeft = PassesLeft - 1
		local NodeVisual = NodeBase:Clone()
		NodeVisual.Parent = game.Workspace
		NodeVisual:MoveTo(Node.Position)
		Node.Visual = NodeVisual
		table.insert(NodeList, Node)
	end
end

CreateGrid()

task.wait(3)

print("Begin The Purge")

for i, Node: Node in NodeList do
	local OvParams = OverlapParams.new()
	OvParams.FilterType = Enum.RaycastFilterType.Include
	OvParams.FilterDescendantsInstances = NavMesh:GetChildren()
	OvParams.BruteForceAllSlow = true
	if table.find(game.Workspace:GetPartsInPart(Node.Visual:FindFirstChildWhichIsA("BasePart"), OvParams), NavMesh.PrimaryPart) then
		print("found", game.Workspace:GetPartsInPart(Node.Visual:FindFirstChildWhichIsA("BasePart"), OvParams), Node.GridCoordinates, i)
	else
		Node.Visual.PrimaryPart.Color = Color3.new(0.388235, 0.368627, 1)
		table.remove(NodeList, table.find(NodeList, Node))
		print("not found", Node.GridCoordinates, i)
	end
	task.wait()
end
3 Likes

I know no one commented, but the solution was that i was removing the node from the table while i was iterating trough it, which mas making it seem like it skipped nodes when it only was the node being pushed back because of the deletion.
i just made it so it adds the node to another table and then iterates through that one to delete them from the old one

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.