This last weekend I wanted to tackle NPC avoidance while moving. As you might recall, if two NPCs collided with each other during movement, they would just stop and wait until the path was clear. And of course, that would never happen if both NPCs are waiting! As a reminder, this is what it used to look like:
At first I tried using Detour Crowd, which is part of the larger Detour project that I was already using for basic path finding. Unfortunately, I couldn’t get to a place I was satisfied with. NPCs would overshoot their destination and vibrate as they inched towards the finish line. But more importantly, they didn’t really seem to avoid each other, instead just rubbing against each other and letting the cylindrical collider do most of the work. I’m sure this is down to user error, but I set off to find alternatives.
At this point I discovered the landmass and rerecast libraries. While building Recast and Detour was never an issue, the idea of replacing C++ dependencies with pure Rust was attractive. I was successfully able to do the replacement without any degradation. The next step was to integrate the agent navigation and avoidance features. After some tweaking, I finally got something I can live with for the time being:
The slow down that the NPCs do when negotiating past each other looks a bit strange, especially because they immediately accelerate and decelerate. But it works well enough for now. At some point I’ll need to take a closer look at the underlying code of landmass and customize it for my own uses.