Pathfinding on terrain

So i have a monster NPC, and made a simple pathfind script.
But it tends to get stuck like a lot on terrain?

https://gyazo.com/e1061984d7766a86f74319cabee55179
He just gives up?

So a lot of people tell me to use raycast and i’ve tried to search around but i have no clue to how to do it, Any better ideas, If not how will i use raycast?

Here’s my current script

local Human = script.Parent:WaitForChild("Monster")
local Torso = script.Parent:WaitForChild("HumanoidRootPart")

local PathArgs = {
	["AgentHeight"] = 10,
	["AgentRadius"] = 18.5,
	["AgentCanJump"] = true
}

function Move()
	local goal = workspace:WaitForChild("briankiller8").HumanoidRootPart.Position
	local Path = game:GetService("PathfindingService"):CreatePath(PathArgs)
	Path:ComputeAsync(Torso.Position, goal)
	
	local Waypoints = Path:GetWaypoints()
	
	for _, waypoint in pairs(Waypoints) do
		local part = Instance.new("Part")
		part.Shape = "Ball"
		part.Material = "Neon"
		part.Size = Vector3.new(0.6, 0.6, 0.6)
		part.Position = waypoint.Position
		part.Anchored = true
		part.CanCollide = false
		part.Parent = game.Workspace
	end

	for _, Waypoint in pairs(Waypoints) do
		if Waypoint.Action == Enum.PathWaypointAction.Jump then
			Human.Jump = true
		end
		Human:MoveTo(Waypoint.Position)
		Human.MoveToFinished:wait()
	end
end

while true do
	wait()
	Move()
end
4 Likes

This issues you’re seeing are very likely related to the AgentRadius you’ve set. Just as an experiment try setting it to 1 or 3 or something

2 Likes

Isn’t agentRadius the how wide the npc is?

1 Like

Yeah, it looks like the Pathfinder is behaving as expected for a radius of 18.5… minus the points up on the wall, that is a tad odd.

1 Like

Well it’s behaving better with 1, But it still gets stuck

1 Like

Is there anything above you in the example you showed?

1 Like

This is the hill, It gets stuck on every single time.

Try decreasing AgentHeight too?

To how much do you think would be good?

EDIT: i put it to 3 and it still gets stuck on random stuff

Just start with 4 or 5 and see how it goes. If you turn on the NavigationMesh it helps a bit too

1 Like

I tried navigationMesh and theres a lot of terrain sticking out above the purple, So.

It’s just for visualization purposes. As far as I know there’s no way to make it more accurate.

Hmmm, Might just remove the monster and scrap the game lol, There’s way too much not working with the annoying fella

I guess you could. Sometimes in situations like this it helps to add in invisible blocks to help correct the mesh. If you put them in a collision group that default can’t collide with then it won’t change the way the players move around on the terrain at all.

1 Like

Yes i figured i’d do that, But then players could hide in this spots and the monster wouldn’t be able to get them, Which would be a big flaw.

If you don’t make them super tall I don’t think that would be an issue? Or design your terrain around the pathfinding… that sucks though.

Yeah, well we finished the entire map so this will suck a lot, Unless i find a way around it.

We have actually had a similar issue with our pathfinding, where the AI would attempt to navigate an elevated portion of the path such as that. We ended up settling for a more simple approach, because we didn’t really need the pathfinding after all.

1 Like

Well our npc will need pathfinding, Since there are stairs and stuff.
It can’t just bump into a wall and make the people survive the entire round…

I’ll find something i hope

1 Like

It strikes me as odd that it doesn’t move. Maybe I jumped to the pathfinder too quick. Let me take another look.