How to increase obstacle diameter

Hey,

I am having an issue where the diameter of my obstacles is tiny, therefore resulting in my using moving through walls or other obstacles. Here’s the picture:

I use a tilemap, however, I don’t use tilemap colliders for obstacle detection, but instead update which tiles are obstacles or walkable using AstarPath.active.AddWorkItem, like so:

Screenshot_2

How can I increase the obstacle diameter? I’m assuming this needs to be done through code, because I cannot do anything from the inspector once the game is running, since everything I do is through code.

Hi

You cannot really do this if you are modifying the graph manually like that.
However, if you use the beta and create a custom grid graph rule then you can use for example the ‘erosion iterations’ setting and it will work automagically.

See https://www.arongranberg.com/astar/documentation/dev_4_3_41_5623d52b/gridruleswrite.html

Really? That seems like a super basic thing to do - the only thing that I’d be doing differently is using a hardcoded diameter value. I’d like to explain my use case so you can understand why I’m having to jump through these hoops.

1.) I wanted to just use the Tilemap colliders originally, however, picture a scenario where I have 2 tilemaps on top of each other. One is from the Ground, other for any Vegetation. What if I want a tree to be an obstacle, but don’t want it blocking the area behind the treetop? In this case because of the collider it still gets detected by an obstacle, as shown:

Screenshot_1

And besides, in this case just to demonstrate I used tilemap colliders to detect where the obstacles are, and the diameter option doesn’t seem to be changing the “size” of the red squares around which Agents navigate, it just makes more of those small ones around the area. Maybe it does function as intended but the visualization is very misleading. (I want them to not cut corners).

2.) In case this really isn’t an option to me, and I have to resort to erosion, would you be able to explain a bit more on what erosion is and how it works? What sort of rule would I have to write and what would it do?

I just want to increase the little red box so people don’t look like they’re cutting into obstacles.

I would really appreciate if you could assist me with this when you have the time, since my entire development is halted because all of my upcoming work depends on pathfinding.

Thank you!

Hi

I don’t think the tree should be generating a collider near the tree top in any case. A player wouldn’t be blocked when walking there, would they? So I think you need to configure your sprites not to block in that location.

It is indeed. And it is well-supported using the grid graph’s diameter setting or the erosion setting. However, if you go through every node and override its walkability value, then you are just telling the grid graph to throw away whatever work it did and just use the values you provide.

The grid graph is represented as a bunch of tiles that are either walkable or not walkable. When the graph is generated it does a check for each node to see if there is any obstacle in a circle centered at the tile with the given diameter. So increasing the diameter setting will make more nodes around the obstacles unwalkable (red). You can also increase the resolution of the graph by reducing the tile size field.
You can see the visualization more clearly if you enable ‘Show Surface’ and ‘Show Outline’ in the grid graph settings, which you seem to have turned off.