Welcome to the forums @drw89!
It's not a bug, it's how you are moving your pong ball. There's a few things going on that are causing the issue.
The first is that you are moving the ball by modifying it's position every _process
function call (every frame). This doesn't really work for the RigidBody2D node, as it's physics are simulated by the physics engine, so what is happening is you are fighting the physics engine every time you move it. I'm not sure why moving the mouse overrides the physics engine though, that is a bit of a mystery.
Regardless, to fix the first issue, I would recommend either setting the RigidBody2D mode to kinematic
(telling the physics engine you will control the physics) or using a KinematicBody2D node instead. Of the two, I would suggest using a KinematicBody2D, as then you can get more fine tuned control and can use MoveAndCollide
to move the ball instead of directly modifying it's position.
Another issue is in how you are checking to see if the ball reaches the edges of the screen. It's a minor issue, but if you don't add a few pixels to _screenSize.x
, then it will jitter back and forth right by the paddle once the first issue is fixed. I believe it is occurring because both the condition and the Area2D both trigger. Adding 10
to the value seemed to fix it for me.
(I also changed _Process
to _PhysicsProcess
so it's tied to the physics frame rate rather than the visual frame rate. This can keep it better in sync with other physics objects)
With those changes done, now it works as expected. I uploaded the modified project :smile: