0 votes

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.

in Engine by (15 points)

1 Answer

0 votes
Best answer

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).

by (247 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.