![]() |
Reply From: | Dlean Jeans |
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
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.
jjcdesamito | 2019-06-11 10:32
No scripts needed. I think you might have the wrong settings. Do a double check.
Dlean Jeans | 2019-06-11 10:42
Proof that it works:
Dlean Jeans | 2019-06-11 10:50
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!
jjcdesamito | 2019-06-11 11:16
This works like a charm, I also found that going into the generated PoolVector2Array under the Polygon type one can easily edit the coordinates to make pixel perfect rectangular bounds.
There might be an easier way to create a perfect rectangle and segment it but this approach worked well and took all of 5 minutes to create two separate zones to be used to separate different pong paddles.
BenVella | 2020-09-26 19:37