A* Pathfinding Project

Use colliders to define walkable areas


#1

I am working on a 2D game. This may surprise you but it is actually easier for me to use colliders to draw the walkable areas of the game, as opposed to using colliders to define the obstacles.

Is it possible to do that? Have a layer where the colliders are used to define walkable areas, and anything else is an obstacle?


#2

Hi

I think the best way would be to subclass the grid graph like this:

using pathfinding;

public class MyGridGraph : GridGraph {
	public override void RecalculateCell (int x, int z, bool resetPenalties = true, bool resetTags = true) {
		base.RecalculateCell(x, z, resetPenalties, resetTags);
		var node = nodes[z*width + x];
		node.Walkable = !node.Walkable;
		node.WalkableErosion = node.Walkable;
	}
}
// In an editor script
using pathfinding;

[CustomGraphEditor(typeof(MyGridGraph), "My Grid Graph")]
public class MyGridGraphEditor : GridGraphEditor {
}

I haven’t tested this, but I think it should work.

Now you should be able to add a new graph of the type My Grid Graph and that will have all walkability values inverted.


#3

Works great! Thanks man!