Accurate Collision Testing

Been playing around with the free version of A* Pathfinding Project and it’s been awesome so far. I’ll purchase the pro version when I begin to optimize the game.

I’m making a game in 2D, top down view, and followed this tutorial to set up my 2D A* Pathfinding: but modified for my game.

I might be missing something on the documentations, but I’m having difficulties finding the appropriate code/settings to modify to make the A* Pathfinding accurate/take into account of the pathfinder’s collider.

Here’s a screenshot I’ve taken to describe the problem I’m having:

The green rectangle drawn in green is the actual collider for the character (Box Collider 2D). The green line is the pathing waypoints drawn from A*.

What should happen: The green rectangle should remain inside the blue lines (walkable nodes). However, the above screenshot shows that the green rectangle has already passed the walkable nodes and is colliding with the object. In real time, the character slowly moves down to the next waypoint, but it’s not smooth because it’s constantly colliding with the object to its right, somethings it’ll move up and down because A* searches for a new path.

How do I make it so A* takes into account of the pathfinder/seeker’s collider? I feel like I’m missing something in the documentation that will solve this problem.

Many thanks,


Glad you like the system! :smile:

The first thing to note is that the lines that you see are the connections between nodes, node the border of the graph. So from the graph’s point of view it is completely valid for the center of the character to be anywhere on those blue lines.

To increase the size of the margin the graph has you should tweak either the Grid Graph -> Collision Testing -> Diameter setting or the erosion iterations setting. But prefer the diameter setting first since that is usually more accurate.

You may have to increase the resolution of your graph however since currently it looks like it doesn’t have enough resolution to be able to accurately take the environment into account (Grid Graph -> Node Size).

Thanks for the quick reply! I assume for every new agent with different sized colliders, such as a large boss or car, will require a new grid graph with its own collision testing settings? Is it possible to have more than 1 active grid graphs?

For example, a small enemy can fit through some ‘cracks’ and that’s the shortest path to the destination whereas the big enemies needs to go around the ‘cracks’ to reach the destination. If I were to use the current grid graph settings, the large enemy would move up and down between the cracks and not go around it.

In another words, is it possible for each agent to have its own collision testing or can multiple grid graphs be active at the same time for different agents?


That is one way to do it.
You can also use erosion to set different tags on the nodes. This can work to some extent but does not give you a very high resolution.

You can have lots of grid graphs. You will need to specify which graph to use as a parameter to the StartPath method.

However keep in mind that a graph uses up memory so you might not want to have too many.

Awesome! Thanks for developing A* for Unity and for the fast support! Got everything working and everything I needed answered.

Glad I stumbled across this project and happy it supports 2D off the bat. Saved me many hours. Just bought the pro version via PayPal to support this project and I’ll explore the pro features soon.


1 Like


I hope you will be happy with it.

PS: Check out the beta version. I am soon releasing version 3.7 so you might as well use the latest beta which is 3.6.8.
The docs for 3.6.8 are also a lot better in many areas compared to 3.6.