Confused with NPC movement and tile detection

Godot Version

4.7

Question

Im Making a game that has map editing and I want to have NPC’s move only on the sidewalk. How do I get them to only be able to move forward and if they detect something other than a sidewalk they turn? Do I need to create a second TileMapLayer only for sidewalks?

One approach is to add a tileset collision layer and define colliders on every tile except the sidewalk tile(s).

What about the movement?

When all the tiles except sidewalks have collision, the only tiles the npc can walk on is the sidewalk. Collisions with the non-sidewalk tiles will keep them on the sidewalk.

As for detecting collision and turning, you can raycast to find a clear path or randomly turn left/right after colliding during move_and_slide().