+1 vote

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.

asked Dec 31, 2019 in Projects by kronopy (21 points)

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

1 Answer

0 votes

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.

answered Dec 31, 2019 by vivavovuve (28 points)
edited Dec 31, 2019 by vivavovuve
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.