Pong: How to block paddle without colission shape

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

So I am making a sort of Pong game as my first project in this engine, but I hit a dead end. The game has 4 paddles on each side of square (arena), so I need to keep the paddles inside the arena, while the ball can exit any side of the arena. I tried having a collision shape with and exit function, combined with static object collisions shapes at the corners to keep the paddles in, but then they become obstacles, and the ball can’t exit trough there. Is there any code or way, in which I can set the space in which the paddles can move without using collision shapes, or anything like that? Thank you.

Have you also tried tinkering with the collision layers and collision masks?

Ertain | 2019-12-31 19:43

:bust_in_silhouette: Reply From: vivavovuve

You don’t need to avoid collision shapes, you only need to make sure the ball and the new collision shape(s) don’t share the same mask and layer. Newly created shapes default to mask/layer 1. You’ll want to set the paddles, the “walls” and the ball to individual layers, and then make it so the paddle mask interacts with both the wall and the ball layer (and the masks of each of these should interact with the paddle layer), but the ball mask should not interact with the wall layer and vice versa. If the paddle has layer 1, walls 2 and ball 3, the paddle mask should be 2 and 3. The ball mask should be 1 only.
The buildup of these walls, provided I’m understanding you correctly, should probably be a StaticBody2D with a CollisionShape2D child.