Help with making pathfinding system less heavy and laggy

I’m making pathfinding system for monsters that are basically big rolling balls simply put and its insanely laggy and I’m really stuck on how to fix it. I’ve added weird functions to try and cut corners with node generation and it barely makes it more lag friendly but also leave the whole system dodge feeling.
made dodge

function PickPart.Pathh(Debug,Siza,Ignore,Start,Go,Parents)	
	Start = Vector3.new(math.round(Start.X*10)/10,math.round(Start.Y*10)/10,math.round(Start.Z*10)/10)--Rounding to makes it easier to read
	local Call = {} --List of every node made
	local AllPo = {} --List of All nodes that can make new nodes
	local Weall = {} --List of every blocked node

	local Repan = RaycastParams.new()
	for i,v in Perenats:GetDescendants() do
		table.insert(Ignore,v)
	end
	Repan.FilterDescendantsInstances = {Ignore}
	Repan.FilterType = Enum.RaycastFilterType.Exclude--Stuff for Parts that can we walked through
	
	local function Moge()--Makes blocks for debug mode to see the path
	end

	local function Lans()--Checks for walls or holes if there are no walls near or holes it returns false
	end
	local function Mae()--Changes colour of path markers for debug mode 
	end

	local function Reyaing()--Sends rounds Vector3 and sends rays to make sure the block placed isnt in a wall
	end
	local function Loog()--Executes Loo and checks if input vector3 is already in a list of nodes to prevent overlapping and uses rays to check for walls
	end
	
	local function Mega()--Makes 8 nodes around a input vector3 and returns the closest one to the targeted destination
	end
	
	while true do--Combines all past functions and loops until it gets to the target or if it loops 8000 times, Fires Mega gets all of the possible nodes adds them to a list makes the closest node inside the said list then sends rays to the targeted position and makes nodes at the position to attempt to make it all faster and reach the destination sooner
	end

	while true do--Makes a path using nodes and returns it to the script that called the function
	end
end

I get that that didn’t explain much but most of my script is written in a really dumb way making it so I need to translate so normal people who don’t write scripts like 4 year olds can read it.

please ask me to elaborate anywhere on anything

I find it nice that you’ve split up your script in areas (functions).

A useful next step would be to profile each area and see what part of the script takes the most amount of time.

Once you figure out which areas are slow, try optimizing them separately or ask for help here (with relevant code).

Ended up being a very helpful suggestion a single function was slowing the whole system down

1 Like

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