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.
If I close up this opening, a path is successfully created and a house can be placed.
Here are the walls in which the path is created inside:
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.
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
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?]
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.
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.