The ball being an static body is odd... I suspect the Area2D
is not detecting the static body at all, see the issue: Area2D does not detect moving StaticBody2D.
I would like to encourage to change the ball to be either a CharacterBody2D
(KinematicBody2D
in Godot 3.x) or a RigidBody2D
. Your code should be easier to adapt to CharacterBody2D
/KinematicBody2D
as you can continue to move it by the same means.
The RigidBody2D
might save you the code for the ball bouncing (you might want to remove gravity), but you need trickery to teleport it...
Teleporting a RigidBody2D
:
PhysicsServer2D.body_set_state(
rigid_body_2d.get_rid(),
PhysicsServer2D.BODY_STATE_TRANSFORM,
Transform2D.IDENTITY.translated(Vector2(1.0, 2.0))
)
Note: If you are using Godot 3, you would use Physics2DServer
instead of PhysicsServer2D
.
Consider also using areas around the playing field, either using big RectangleShape2D
or WorldBoundaryShape2D
(which is intended for this use case).
For advice on which physics body to use consider: When should I use a KinematicBody or a RigidBody for 2D platformer characters?
body.position = Vector2(550,325)
I don't know if this is a smarter solution (You could also use groups so you only move the ball). \$\endgroup\$