Pathfinding: NPC gets stuck around corners

What do you want to achieve?

The NPC that I have made, a monster that patrols around the area, is supposed to move from one point to the other using PathFindingService.

The monster will avoid the walls in its way and reach the green points. The point to which the monster moves is set at random after each iteration of the while loop.

What is the issue?

The monster runs fairly well for most part. But quite frequently it keeps getting stuck around corners and doesn’t move for a few seconds. It sometimes even runs into walls.

A line of code was added to help the monster in case it runs into walls/corners. However, that line of code does not run, indicating that it is the path created by PathFindingService that makes it run into walls and corners.

What solutions have you tried so far?

I started to try fix it by increasing AgentRadius param of pathParams. Even after increasing it to quite a large value as 15, it kept hugging the wall. I kept the walls farther from each other, to increase the potential area through which the NPC can walk but it still does not work the way as intended.

I am clueless about what to do to solve this. I have looked around devforum but I didn’t find any suitable solution.

Here is my code: (It includes some more code which is a buggy player follower on sight.)

Here is a video for demonstration.


(apologies for the laggy video, it wasn’t like this when I recorded.)

1 Like

Have you tried setting the AgentRadius to the size of the monster?

Yes of course I have. As that didn’t work, I thought of increases the radius even more (as I have mentioned in the post). It didn’t help.

Question. In the video do you happen to know which point your NPC is trying to go to when it gets stuck to the wall?

Have you tried increasing the number of waypoints between each path?

1 Like

Increase number of waypoints? Is there a way to control that?

And I think the NPC was probably moving towards the green block on the bottom right.

Ah, sorry I meant WaypointSpacing. You can edit this the same way you edit the AgentRadius, AgentHeight, etc. A larger number you give it means the distance between two way points are larger.
I guess you can play around with the values and see if anything helps?

1 Like