Have all areas be unwalkable and place walkable zones?



I’m making a 2d-game where I want to have all of the background be an obstacle unwalkable to start off with, and then be able to place out tiles where players can walk. However when I try to do this, the background that I have marked as an obstacle overtakes all the walkable tiles I place above it in the “order in layer”, marking those tiles as unwalkable as well.

Is there a way to do what I want? :slight_smile:



If you use a grid graph you could enable ‘height testing’, but set the height testing layer mask to “Nothing” and make sure that the “Unwalkable when no ground” setting is enabled. That will make your whole grid unwalkable.

Then you could use graph updates to mark tiles as walkable (see https://arongranberg.com/astar/docs/graph-updates.php)



Thanks for the answer, I’ll try this out and if I have any problems I’ll get back to you here :slight_smile:


Hi again! Just wanted to give an update on how it went.

I managed to get it to work without having to using height testing. I wanted to use 2d physics and height testing required 3D.

The simple solution I found was to follow instructions you gave in an earlier answer:

" If you configure it so that in the normal case the walkways are unwalkable, then you can simply add

node.Walkable = !node.Walkable;

Right before this line in the GridGenerator.cs -> GridGraph class -> UpdateNodePositionCollision method.

node.WalkableErosion = node.Walkable;"

So I just added: node.Walkable = !node.Walkable; in that script and now I can use the obstacle layer as a way to mark which tiles I want to be walkable instead. Super simple and nice.

If there’s any downside you know about when doing things this way, please tell me. Right now, it seems to work really nice, and was a very easy thing to do.



That sounds like a good solution!