Making unwalkable walkable

Hi Aron,

Just come back to using Astar now most of my other game code done. The new 2d AiLerp is exactly what I need for my current game!!!. Just a bit stuck though.I have searched these forums and docs but can’t find the answer.

I have my game board which is just a maze were the walkable floor is made up of sprite tiles. There are no other sprites/walls that can be tagged as obstacles. A big quad with a texture on acts as the background scenery and is not on the same plane. As there are no walls or obstacles to use when scanning the only thing I can think of is have the maze path used as the mask and then make that layer walkable instead of unwalkable. Is there a way around this?




So you mean there are floor sprites, but there are simply no sprites at all where the character should not be able to walk?

Hi Aron,

Thanks for the quick reply.

Yes you are correct. The floor is essentially a floating maze path. Nothing else. All the background scenery is a texture on a quad in the background.


The exact mode you are looking for does not exist out of the box. You can make it work by some relatively simple changes to the code however.
But I think the easiest approach would probably be to add some 2D colliders around the edge of the maze, only colliders, no sprites.

Here’s an image to clarify. Thanks again.

Just seen you post. There are quite a few levels so it may be quicker for me to change the code. Any pointers as to which I should be looking at would be appreciated. I was hoping I could it would be as simple as changing iswalkable = !iswalkble or something. I am learning but looking at your code you are light years ahead of me with programming.


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;

Hi Aron,

Really grateful for this help you are giving. I have altered the script as advised and have set the collision testing to nothing but the floor layer as it’s the only thing there. Nothing happening though. I have tried changing all the masks and inverting the selection and also selecting use 2d physics. Only response I get is when I have 2d physics off and the height testing is set to unwalkable when no ground. It just walks anywhere then and not on the path.


Just had a breakthrough. If the height testing mask is set to nothing and the collision testing mask set to floor layer. It will run but only if scan in play mode. I doesn’t seem to be picking it up on startup even though scan on awake Is selected.


So you should enable 2D physics and set the collision mask to ‘Floor’ since that would normally make the walkways unwalkable.

The graphs are scanned in Awake. I am not sure how you generate your levels, but if they are generated during runtime, they might not be generated when the graphs are scanned. If so, you can call when the levels have been generated to rescan the graph.

Thanks. For some reason it only works when 2d physics is off and height testing mask is set to nothing. So I will probably have to do the you mentioned.

I don’t know what you think about this method I am using but taking your advice today I think this is a great functionality. From my test now I can use 2d toolkit or another tile mapper and just draw the paths making sure they are on the correct layer. Nothing else needed. This is vastly quicker to produce than adding colliders around the paths. If you built it in as standard I am sure others would be able to make use of it.



Are you using 2D colliders or 3D colliders?

Good point. The 2d is not going to be visible and are used as an invisible track system for 3d meshes that are child objects of these. I had added the 3d colliders early in dev but can swap all this out now.


Ok, that explains why you need ‘2D physics’ set to false, I thought you were using 2D colliders. It doesn’t really matter if you use 2D or 3D colliders, use whichever works best for you.

Thanks for all the help Aron. I can get testing performance on the windows phone now.

I just went to the asset store to give astar a 5 star rating but I had already done it a while back.