Support Forum

Diagonally entering a sinkhole but not leaving it again

We are using an AIPath movement script on a GridGraph.
The bug happens with and without a RVOController.

There is some sort of sinkhole in the GridGraph, see the screenshot:

I read that units on a GridGraph should not be able to pass diagonally unless there is at least one horizontal or vertical adjacent reachable gridnode:

But if I send this unit to move into the sinkhole, the unit will move to the closest point,
then stand there briefly, then decide that it can actually progress to the original path goal.

I guess what happens is that the unit arrives exactly at the corner of the gridnode, or perhaps some effect like rounding / floating point imprecision of the position then makes the unit pop out on the other side of the corner, so that it can continue the path on the other side.

It’s not so much a problem that the unit can pop out, the problem is that it can’t get back anymore.

We can very easily create such a situation when creating levels and its almost impossible to avoid. We had the bug in both of our demo levels.


Sorry for the late reply.
Yes, this can be an issue. And yes, it is caused by floating point errors when the agent is exactly at the corner.
If possible, you can set the ‘erosion iterations’ setting on the grid graph to 1. This will make it effectively impossible for this case to occur. But you might need to tweak other grid settings to make sense for your game.

Is it true that it will make it effectively impossible for the case to occur?
It would depend on the implementation.

Consider this example where white is walkable, black is obstructed, and gray is eroded:

Or if erosion only expands horizontally or vertically, not diagonally:

If the erosion mechanism is trivial and only appends a margin of 1 everywhere, this graph could appear and it wouldn’t really make it more or less likely to get these situations with arbitrary grid graphs I would guess.

An approach in deterministically avoiding these “diagonal entrances” could be when scanning the graph or a graph subset, to detect such “diagonal entrances” and erode only there / block the diagonal entrance.

Our current workaround is to find these sinkholes with manual inspection and add a manual obstruction over it, but that won’t work with dynamic obstructions (such as buildings built during the gametime).

Actual example with erosion iterations = 1

Oh right. I forgot erosion doesn’t expand diagonally.

You could try to attach the NavmeshClamp script to the agent. It’s not used much these days, and it’s not mentioned by the docs, but it might just solve this problem if we are lucky.

Even with diagonal erosion the bug can occur, see first image.

A Linecast each frame for each unit sounds quite expensive.

The most elegant, robust and performant solution would be to detect these cases in the grid and mark both tiles at the “epsilon-passage” as obstructed (perhaps only if a new option in the grid graph is enabled).


Black are obstructed tiles.
Red is the path that a unit CAN take but SHOULDN’T be able to.
Blue are tiles that the algorithm could insert after having detected such a checkerboard pattern.

The catch with this algorithm is that the introduction of the two new tile obstructions (blue) in turn might open up yet another “epsilon-passage” nearby:

Example 2:

So each time the two obstructed tiles would be inserted, one would have to scan the surrounding tiles as well (and potentially the surrounding tiles of the surrounding tiles etc.)

But then it would cover all cases without agents having to do more work or needing any code modifications.