Pathfinding Help Needed (NPCs getting Stuck)

With the code I’ve added there, just use one NPC and see if its creating a path through the wall.
I’ve found problems with parts smaller than 1.5 being clipped through.

It may also be worth asking, what are you calling to generate the path?
There is the Path:ComputeAsync() which is the newer version;
Then theres the older version, which I can no longer find documentation for! It uses a 4x4x4 voxel system, and is more prone to problems with parts not correctly aligned to that grid.

ComputeAsync indeed. Just trying your code out now, I am going to have to dig into a player’s save slot to find a case where the NPC does get stuck

1 Like

Interesting development!

It seems that increasing the size of the walls to 2 studs instead of 0.5 considerably increases the accuracy of the pathfinding. I would send a GIF comparison, but it is taking so long to upload over the Internet that I aborted.

Of course, I can’t yet tell whether this will make PathfindingService sustainable, as I’ve only tested it in 1 player’s save. But it’s still not ideal for some things, such as objects having to now be un-collidable.

Will update tomorrow after more testing. Thanks everybody!

PS: @edenojack that waypoint visualiser is awesome

4 Likes

I thought I would just add in a small tip about network ownership because many people who had asked me about failing npc usually ended up fixing by assigning it for appropriate owner(e.g. most npc’s network owner is server because client does not need control over it )

I had a play about with pathfinding a while back while working on an RPG game. We had some really nice houses but we had to add invisible walls that were several studs thick around the house to make sure it recognised the doors.

Make sure all of your doors and openings are plenty wide enough too. As long as both arms and the torso comfortably fit through it should be okay.

If you want your walls to stay 0.5 for aesthetic reasons, add invisible 2 stud thick walls so they extend 0.75 studs beyond each surface. Most people won’t notice.

2 Likes

Ok, i not am sure if this really can help you, but long time ago i read a topic and the solution was to add Raycasting: For example, if you make a zombie game, i know games in them the zombie stuck in the wall. Now, you can raycast to see if it was a wall before your NPC, and if it was so, then you can recompute thr Path. Else you can yeld a bit, then create the path. Or you can use A* Pathfinding system, hope it helped you. Last chance: Terrain Path With A* Pathfinding, else really can‘t more help.

Solution idea for your collision issue, why don’t you create a collision group for the NPCs and furniture? It’ll be easier to move them around and players can still interact with the furniture. Or is this not ideal ?

3 Likes

A NPC that go through a wall, else this was a ghost :roll_eyes:, not think this was a good idea, but if this can help then why not try.

Pathfinding Service can automatically generate a path around obstacles, but if a NEW obstacle is presented in front of the NPC after the path was already created then it will get stuck.

(you need to update the path AS the NPC is moving or you can update the path when he touches certain objects)
1 Like

Good idea! Why not add Raycasting to this instead using a touched event.

raycasting would be more efficient IMO, i would definitely recommend it, just depends on the design/developer i suppose.

Hey everyone, thought I’d reply and give you an update.

So this is my main struggle right now with the pathfinding. As you can see in the attached image, there are three desks which all have been set to collidable (CanCollide = True). However, you can see that instead of just simply walking around the reception desk, it gets stuck. You can also see the visualised path trying to direct the NPC through the desk.

I’m really confused as to why the NPCs are not walking around the obstacle here. It will re-compute the path if it gets blocked up to a maximum of three times, but even still, it’s still computing the same path each time?!

Thanks for the help so far, much appreciated.

4 Likes

When you create the tween, there is an agent-radius property. Maybe if you decreased that and agent-height, It would work better.

1 Like

Hey, @Alvin_Blox, can you make a place with only your issue as model (scripts included). I not really undderstand why it don‘t work, you can only send us the important objects, we don‘t need the rest. But your choice. Then, have you tried to change the Hipheight of your NPC‘s?

1 Like

Didn’t see there was more!
Have you tried adjusting the agent’s size like @LoveTheBears101 suggested?

Alternatively, are the desks;

  • A mesh part with CollisionFidelity set to Default? Try Box or Hull!
  • Non-moving? Have you tried creating a bounding box for it? This would act as a barrier to stop NPCs trying to move through it!
  • Does moving the desks up slightly change anything? It looks as though we’ve disabled jumping, so it might be attempting to path over it.
3 Likes

My apologies, I also did not see that there had been further replies! I am turning this thread to tracked so that I should get notifications in future

Yes - I noticed the reception desk collision fidelity issues and found that when they were set to Box the NPC no longer tried to walk through them, so that’s that issue fixed. Only flaw with that is that now you cannot walk ‘inside’ the reception desk or stand behind it due to the entire box now being collidable. A small price to pay though, in my opinion, for continued reliability.§

However, I have still noticed that with 2 stud walls , or even thicker, NPCs are still liable to get stuck. This is making me more inclined to create my own A* path finding system as has been mentioned before. I would be very grateful if anybody had their own system they would be willing to share, to give me a pointer in the right direction of how to successfully create one. I have tried a couple of times, but gotten nowhere. Currently I am trying to watch videos of A* implementations in other languages to try and convert into Roblox.

Many thanks for the continued support on this thread - much appreciated.

Cheers
Alvin

3 Likes

There is a good number of tutorials on making an A* pathfinder, I made one a while ago but its not very performant. Do you have any images of the 2 stud walls being pathed through at all?

2 Likes

Apologies for the late response. Yes, I do. I think in the third picture, that is recomputing the path / trying to get them to leave the building as the original path broke - but that also gets stuck :confused: This is why I’m looking into alternative A* pathfinding!

3 Likes

This thread is like 2 months old so you’ve most likely figured it out by now, but like you said, you (and anyone else having similar problems) are probably much better off using an A* system with nodes rather than trying to force Roblox’s pathfinding system to work decently.

It might not look as “natural” as compared to rblx’s system, but at least you can control where NPC’s can walk to. Rblx’s system doesn’t really like to work in tight and complex environments like this.

There are a couple of free plugins by CM32 and StealthKing95 that already have the node placement and A* algorithm figured out so, unless you’re a purist, you can use those.

3 Likes

Hey Alvin, i like your videos lol, Anyway to the topic, what i did to prevent the NPC walking into walls was
Whenever the NPC is set to walk to a Node, it firstly has to walk To it’s Exit Node which has the same name but a “Exit” hanged onto it and then walk into the room, same with exitting that room it walsk to the Exit Node and then to the node inside the room, i use pathfinding too btw.

1 Like