recastnavigation / recastnavigation

Industry-standard navigation-mesh toolset for games

Home Page:http://recastnav.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Agent behavior degrades when there are more than MAX_NEIS neighbors

grahamboree opened this issue · comments

For most cases, we don't care about anything more than MAX_NEIS number of neighbors. Accounting for additional agents has negligible impact on the final resulting behavior, and has a super-linear impact on performance.

This causes problems in very dense situations with large neighbor radiuses. If the MAX_NEIS sized subset of neighbors is randomly chosen, it can miss neighbors that are very impactful to the agent's behavior. It may instead react to a neighbor that is farther away. e.g. #305

Ideally the set of neighbors that an agent reacts to should be both evenly distributed and distance-sorted, such that they provide an accurate approximation of the un-restricted neighbor influence.

The challenge here is finding an approach that isn't so expensive it defeats the advantages of limiting the number of neighbors that an agent reacts to.

In one of my recent crow tests I used modified Detour grid, but sorted the grid cells based on distance from cell center to the query point before accessing the cells. Then, I stopped as soon as max items was full. I limited the max search to 10x10 grid. In the end it was faster, because I was able to reduce the number of max agents to gather (from around 60 to 20). Calculating the visiting order was faster than the random access of the cells. Final 6-8 agents were chosen based on distance/time-of-impact from the agents found on the grid.

For larger crowds (>250 agents) the grid access dominated the calculation, but I found out that doing it 10Hz, on a 50Hz simulation worked fine. Of course depends on moving speed, etc.