Use colliders to define walkable areas

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?

1 Like

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.

1 Like

Works great! Thanks man!

1 Like

I was about to ask the same question, but tried trolling through here first.

This works perfectly. Thank you to you both for asking and answering the question (and creating the package)!

1 Like