2D pathfinding - small gaps problem

Hey,

I have a 2D game, it uses 16x16 grid/sprites
You can see on the image below that when I scan it’s not accepting any tiles that are next to a wall/obstical.
The Obstacle tiles is using Tilemap collider 2d & Composite collider 2D
How can I adjust my settings so it accepts those as well?

I’m using 2D Physics, Colldier type Circle
Currently I have tried changing Diameter, node size etc without luck.
Any ideas?


2

Edit: I can make nodes 0.2 in size for example, but then I will have so many nodes. Hopefully someone knows how I can maintain a node size of 1.

Hi

This is most likely a floating point precision problem. The graph checks if there are any colliders in a circle with a diameter of 1 centered at each node. Your colliders on an adjacent node will just touch that circle. Try reducing the grid graph collision resting diameter to 0.99.

1 Like

Hey, thanks for reply.
I had the same idea, but when I tried yesterday I couldn’t figure it out.
What I forgot is that when I adjust colliders on a tile, I have to manually disable and reenable the collider to force an update.
Now it works! Thanks :slight_smile:
It’s not 100% ideal way because Composite Colldier 2D won’t work now that the tiles has a gap and I have to manually adjust every tile’s physics shape, but it’s a decent work around.
Didn’t find anywhere to adjust the collider other then Sprite Editor -> Custom Physics shape. Perhaps someone knows a better way.
Also have to figure out how to make the NPCs follow the path more correctly, currently they slide a bit too much depending on speed etc - but that’s another story :slight_smile:

Hi

I don’t mean that you should modify the collider shapes, I mean that you should modify the setting A* Inspector -> Grid Graph -> Collision Testing -> Diameter setting.

I tried that as well, and what happend is that I get this odd results - example below

Hi

What mode are you using for the tilemap collider? You should not use the edge collider for best result (I think the other one is called “polygon” mode? I cannot remember right now). This is because the edge collider just generates a collider at the boundary of the mesh, which doesn’t help the system figure out if something is inside or outside the collider.

I’m using Tilemap Collider 2D & Composite Collider 2D

Yeah, but there is a setting called ‘Geometry Type’ for the composite collider 2D.

oh, right - it’s Outlines.
I disabled Composite and it made that one tile correct at 0.97 - Can test with multiple tiles in a second

Edit: Removing Composite Collider 2D and Diameter 0.97 seems to work well :slight_smile: