How would i make npc only walk on path

Hello, so i’ve had some problems with making npcs walk from the blue spot over to the shop without taking a shortcut trough the grass, instead of taking the path.

image

What i’ve tried so far, is where the npcs walking random from path to path instead of using pathfindingservice.
Now they don’t always follow the red line but sometimes also the purple line.

Is there a way i can make them go to a certaint spot without them taking shortcuts?

If I want an NPC to follow a strict path then I find it’s easier to breakup the path into straight lines with invisible parts.
So with your example you could have part1 at the T junction and part2 at the end point of the red line. Then simply loop through all parts of the path with MoveTo, telling your NPC to go to Part1, when it reaches Part1, MoveTo to Part2 etc.

Edit:
If parts of your created path are quite far away from each other then use Pathfinding to reach each part as MoveTo has a timeout of 8 seconds if I remember correctly.

Another method would be to create invisible walls so the npc can’t get onto the grass and make either a collision group so players can walk through them or set CanCollide to false in each players starterscripts.

Polaris-Nav is still in development, but when released you can select the parts that make the path and then generate a navigation mesh on it. You can then assign this mesh to the NPCs you want to only follow that path.

1 Like

What I would do is to create a sort of graph with every junction or part being assigned an node. Then you can use some simple Graph Theory to figure out the route.

Here is an implementation of that I wrote 6 years ago on the free models. Polaris-Nav will be a much better solution though, allowing obstacle avoidance.