Issues with PathfindingService

In my game, I use the PathfindingService in order to move cars from the starting location to a house destination. For some odd interesting reason, if there is a road that’s not closed off, it will fail to create a path.

Example:
This road has an opening right here. The PathfindingService is saying that a path to the house is impossible.
image

If I close up this opening, a path is successfully created and a house can be placed.
image

Here are the walls in which the path is created inside:
image

Does anyone have any ideas as you why it would be doing this?

The only solution to this that I can think of is to just close up road openings that are unused. However, I really don’t want to have it check the surrounding roads each time one needs to be placed.

If anyone knows a fix for this or if they have a better suggestion, it would be much appreciate.

Edit: I should note that the end designation is in the middle of the road in front of the house. It is not the actual house location. Logically, it should not try to go off the road to get to the house because that would not be the shortest path.

2 Likes

Is this caused because there is no opening outside the house?image

Sorry! I just added an edit to the original post. It’s trying to get to the middle of the road in front of the house, not the actual house itself.

1 Like

From what you are saying it only occurs when there is an open road, how bout make an invisible barrier on open unfinished roads


gotcha I’d have to see the behavior of the path before I could help further

Is it possible for us to see some code?

I don’t need code i just need to see a gif of the path blocks when you are trying to place the house

I am unable to get the path behavior because it fails to create a path and therefore doesn’t have any waypoints.

Well then this comes back to the invisible walls instead of scripting the invisible wall with it, just have it already in the model when it is placed

Are we able to see the code of you trying to create the path?

This is essentially it. It’s just creating a path from the start to finish.

function populationControl:driveTo(person, pos)
	local finish = Vector3.new(pos.X, 1, pos.Y)
		
	local parameters = {AgentRadius = 2, AgentHeight = 1}
	local path = pathfinding:CreatePath(parameters)
	path:ComputeAsync(game.Workspace.PathfindingStart.Position, finish)
	
	if path.Status == Enum.PathStatus.NoPath then
		--add error to house
		return
	end
	
	if path.Status == Enum.PathStatus.Success then
	    --move car to house
	end
end

The road models have the invisible walls. The walls are not added nor removed.

Edit:

For whatever reason, I believe the pathfindingservice is trying to do something like this:


and, as you said, the finish point is on the road, which is blocked by the invisible wall.

I’m assuming if you set the final position to before the exit - it won’t error.

This is a complete guess, but what if you increase the AgentRadius of the parameters, the PathfindingService may (or may not) recompute it to follow the road instead [Does your car really have a Radius of 2 studs?]

2 Likes

I adjusted it to 10 and it gave the same result unfortunately. I only had it set at 2 because I USED to have a wall between the road lines in order to have some sort of logical vehicle traffic. However, that became too much of an issue and I removed it all together. The cars are really small.

Hm, thats a shame - this is indeed a very odd issue.

This is an alternative I can suggest, instead of looking at PathfindingService, looking at how you could change your road layout.
(I have no idea how your game mechanics work, but this may work - from looking at the images I’m guessing this is some sort of “city creation” game where you create houses and roads etc.):

Instead of creating a road with an opening which leads to nowhere, how about you use this part instead:

And then, if the user wishes to build on from the road, the game engine will automatically convert to the part you are currently using in your OP so that the roads continue to connect.

I guess the final say is whether you wan’t to create those invisible walls whenever there is an opening leading to nowhere, or if you wan’t to change the road types to suit how the user is creating their roads as they play - unless someone comes up with a solution, of course.

1 Like

For something like this, where it appears you are essentially just connecting nodal pieces of road together, using the PathfindingService may not give you the expected results you’re hoping for (as I assume you plan on having vehicles drive on the road). You may want to look into implementing a pathfinding algorithm yourself, like A*, by treating the road segments as nodes on a graph.

So here is my solution:

Paths are automatically blocked off if they lead no where. Obviously that black wall will be invisible, just showing what’s going on.

Buildings can now be placed when there is a path leading no where. :smiley:

3 Likes