This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm working on a top-down space shooter using rigidbodies like in Asteroids, but I intend to allow the player to travel through a very large area. However, I don't want the play area to be infinite, so I plan to add invisible walls so that the player will be bounced away when they go farther than I want them to be able to go. What is the best way to implement this?

in Engine by (38 points)

2 Answers

+2 votes
Best answer

The easiest would be to stick 4 rectangular static bodies at the edges. Give them collision shapes but no sprites and they'll be invisible.

by (22,191 points)
selected by

Indeed, so far works alright for me, just make sure the walls are thick enough to avoid any possibility for objects to go through them.

0 votes

If you're using add_force or apply_impulse you can use colliders and give the player a bouncy physics material. Another way would be to use an area and use body_exited when the player exits it, direct the player back in or towards the area using translate or look_at, or you could clamp the translation x and y values but that would stop the player instantly.

by (3,259 points)
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.