How to detect if an Area2D is contained within other Area2Ds?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Comrade SparklePony

I have been working on a game that is essentially a 2 dimensional top-down shooter. I want the player to be able to walk on the ground but not off it.

My current setup consists of an Area2D which is the player, and a bunch of “tile” nodes which are instances of a prefab which is just an Area2D. The player is supposed to be able to walk only on these tiles, and not off them. I like having these tiles because I have an idea about how to generate a random maze with them later in development.

How can I make it so that the player cannot step off the tiles? I would prefer to keep my current setup, but if it is unreasonable, don’t hesitate to let me know, as I am very new to Godot and game development.

Thank you.

:bust_in_silhouette: Reply From: lincolnpepper

You’re best option is to put collision rectangles in the tiles that aren’t paths. If you want randomly generated rooms this would be a good way to do it, just start at some point and randomly make a path or a wall in either of the 4 directions and then in the next tile consider where you came from and generate where you can go from there and so on. I don’t believe that there is a built in way to keep a player within a certain tile. You would have to code it, and most of the time you want to do as little coding as you can (you can’t have bugs for code you didn’t write).