NPC with Pathfinding keeps slamming into a wall [SOLVED]

Hello! I am having troubles with my AI code. I wanna make a Granny-like AI script, and I’ve used a few scripts as references (Teddy AI, Piggy AI etc.) to write my own.

THE ISSUE:
The NPC stars slamming into the wall for some reason, even though I’ve added AgentHeight and AgentRadius.

I’m using the PathfindingModifiers BETA feature since that was my only hope and it still didn’t work.

Thank you for your time and if you have any solutions, please tell me because I’ve been trying to solve this issue for a while.

Here is the part of the script that creates a path for the NPC.

local function getPath(destination)
	
	local path = PathfindingService:CreatePath({
		AgentHeight = 4,
		AgentRadius = 3,
		AgentCanJump = true,
		Costs = {
			AvoidZone = math.huge
		}
	})
	
	path:ComputeAsync(Grandad.HumanoidRootPart.Position, destination.Position)
	
	return path
	
end```
2 Likes

does it have to follow the player

yeah, it’s basically Granny’s AI

Do you have unions in your games that are not decorative, like a unioned staircase or wall? If so, you should seperate the unions because pathfinding service cannot compute a path around unions.

If this is still an issue usually changing agentcanjump to false will fix your issue. Sometimes when creating a path it’ll look for parts that may be jumpable and attempt to create that path into a wall based off how you build.

No, the game contains no unions for maps.

I just tried doing that, it didn’t work. He still won’t avoid walls properly.

Ok, I just solved it. I had to change the line

for i, v in pairs(workspace.Map.GrandadMovepoints:GetChildren()) do

to

for i, v in pairs(path:GetWaypoints()) do

Thank you for your help! :smiley: