0 votes

I'm already aware on how to create a wall using collision to prevent player from overlapping an object.

Now I wan't is to prevent the player from moving outside the box or circle or any shape but I don't know if this is possible. Or the only way to do this is create a "C" shape to act as a collider wall?

asked Jun 11 in Engine by jjcdesamito (21 points)

1 Answer

0 votes
Best answer

Use a CollisionPolygon2D and set the Build Mode to Segments.

It's easy to build a box shape inside the editor. But if you want a circle or any shape:

  • Create a Sprite with a texture of that shape (an image of a circle for example)
  • Press Sprite > Create CollisionPolygon2D Sibling

Images from Github

answered Jun 11 by Dlean Jeans (3,505 points)
selected Jun 11 by jjcdesamito

Hi, Thanks for replying!
I tried your suggestion but this does not prevent my player from going outside the polygon I created. Do I also need to attach some scripts?
I want my player movement to be contained only inside the polygon like trapping him inside an invisible bubble.

No scripts needed. I think you might have the wrong settings. Do a double check.

Proof that it works:


Thanks for the pic.
I didn't know I should use StaticBody2D. (I tried using Node2D as parent)
It works now as expected.
Thank you!

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 How to use this Q&A? before posting your first questions.