How To Make Pathfinding Service Only Go Above Certain Objects?

You use costs to make the pathfinding avoid certain materials and any object with pathfinding modifiers where you have to label the parts so that the pathfinding can avoid it, how can i use costs so it can only go on a specific label? for example i want a car to go only on the streets and not the sides.

You can just put every thing thats not a street into a folder then loop through every descendant in that folder and set it to math.huge cost

1 Like

So put large CanCollide blocks on the areas that aren’t streets and make their cost math.huge. This is explained at the bottom of the Pathfinding documentation in the Work With Regions section.

@talis783 if there were a million parts that weren’t streets that’d slow down your pathfinding and your game to a crawl.

the problem is that the map is unknown, so i want to iterate on all the streets in the map, and make the car only go on the street part

Is it random generated, or does the player build the map their own way?

the player changes the map however they want.

Bumping because I need to know how to make an npc only go on the roads on a random map.

you could try add a pathfindingmodifier object inside the road part and adjust the cost inside the script so that the npcs stick to/avoid that part

doc link is here

Doesn’t the cost only make things not traversable? This won’t work since I only know the roads and not much else. How to adjust the cost so that the NPC only goes on the part?

since the default cost for everything is 1, you could try setting the cost of the pathfindingmodifier to something below 1?