Calculating Street Paths

Hey, DevForum :wave:

I’m currently working on a single player story / freeroam game, but I am struggling a little bit with the NPC system I am creating.

So, one of the first features I’ve started working on is NPC’s having items, such as clothing. But, to purchase the items the NPC’s are going to drive to the clothing store right. So, let me stop rambling. I am attempting to calculate the path of the NPC to drive. So they get into the car, lets say it’s just the car is on the road.

I need some help learning on how to calculate the path, I do not want to use path finding service because It is just going to go through the buildings / through the empty plots. I am attempting to have it where the car pulls to an intersection, lets call that intersection point A, they need to get to point B (view diagram below). Does anyone know a good algorithm that I could learn to calculate the best path for this? And if so, is there a specific way I should implement it in roblox?


A ----------- D
C ----------- X
L ----------- B

You can use PathfindingService to achieve this, for the parts you don’t want the NPC to walk on, add a pathfinding modifier there and make the cost of that math.huge, that’ll exclude it and will make the NPC never want to go there.

1 Like

I am not experienced and I think you should just use default pathfinding but I have an idea on how this works:

Assuming all your blocks are the same size, find change in X and change in Z, then drive that amount in X and then Z, making an L shape

He/She said :

I don’t know why the preference but they do they…

I know that they said that, but it’s way easier and more accurate to use a completely functionally, well tested and built-in pathfinding algorithm rather than one you just made. (S)He may have never heard of PathfindingModifiers which could be the reason (s)he didn’t want to use PathfindingService.

1 Like

Actually that interpretation make sense now I re-read the post…

There’s actually an open sourced Roblox showcase that Roblox published years ago: The cars and NPCs follow the roads and sidewalks, and the NPCs can drive.
It’s a little bugged, but you may be able to learn how they did it by editing it.

Glad that made sense :)..

Thank you all so much for your replies!

Looking at your answers, I’m going to experiment with PathFindingModifiers as I did not know they existed from my research.

I will update this thread if I end up going another way for learning purposes! Thank you all again.