Godot Version
v4.2.1.stable.mono.official [b09f793f5]
Question
Hi, this is my first time posting! I’ll try to make this as descriptive as possible, but please bear with me if you need me to provide more info.
I’m trying to make a sim with a lot of NPCs moving around a building to perform tasks. While my implementation of pathfinding “works”, I’ve run into the issue that the paths NPCs take are very unnatural looking and usually cause the character to rub against walls (since it’s technically the shortest distance). The main aspect of this I’d want to address is to have the NPC walk close to the center of the hallway if they’re the only one there.
Here’s what I’d like the pathfinding to look like
Here’s what it ends up looking like in practice
And here’s a screenshot of the game itself to illustrate the problem. Note how the characters never go through the center of the doorway and are constantly hugging the wall.
This is the NPC I’m using to troubleshoot pathfinding
I have two vague ideas on how to improve this, but don’t know enough about pathfinding in Godot to understand how I would begin to implement them.
-
Have some kind of “personal space” collision shape that only interacts with walls. Somehow this would need to not be so solid that it would prevent the character from passing through doorways or standing in corners, but solid enough to cause them to set their path at least a few feet away from the wall. Also this would need to not cause any kind of actual friction that would effect the NPC’s speed, and only prevent their path from being drawn too close.
-
Use an AStarGrid2D with the tilemap. While I don’t want grid-based movement for my game, reducing the amount of possible coordinates might lead to somewhat cleaner looking paths. I’d like to avoid this though, since it might not look right when I scale up the amount of NPCs in the level.
If anyone’s ever had to deal with a similar problem like this or have any suggestions on how I could do the personal space idea, I’m all ears. Honestly if there’s a good-enough solution that only involves tweaking the navigation agent settings, I’d settle for that! At this point in time, I don’t really care how resource intensive the solution would be. I’ve watched a lot of the tutorials that are out there on pathfinding, but they’re mostly about simple enemy movement, so they never address having the NPC avoid sliding off walls in the first place.