Problem with pong ball not bouncing but getting pushed by paddle

Godot Version

4.4.1.stable.mono

Question

Problem with pong ball not bouncing but getting pushed by paddle

I am trying to create a pong/brickbreaker style game to learn a bit about how godot works, but I am stuck with a problem on recreating the expected behavior from this games.

My problem is that when the ball hits the side of the paddle, the ball does not bounce, it gets stuck to the side of the paddle and moves along side it.

This problem only occurs when the platform is moving.

Godot_v4.4.1-stable_mono_win64_O3JT9MsHPZ

Here is the code:

Ball.gd

class_name Ball
extends CharacterBody2D

const SPEED = 600.0
var direction
var target = Vector2()

func _physics_process(delta: float) -> void:
	
	#Here so i can move the ball where i want so i can test it easier
	if Input.is_action_just_pressed("left_click"):
		target = get_global_mouse_position()
		direction = (target - position).normalized()
		velocity = direction.normalized() * SPEED * delta
	#Here so i can move the ball where i want so i can test it easier
	if Input.is_action_just_pressed("right_click"):
		global_position = get_global_mouse_position()
		
	var col = move_and_collide(velocity)
	if(col != null):
		if (col.get_collider() is Paddle):
			velocity = velocity.bounce(col.get_normal())
		else:
			velocity = velocity.bounce(col.get_normal())

Paddle.gd

class_name Paddle
extends CharacterBody2D

const SPEED =600.0

func _physics_process(delta: float) -> void:

	var direction := Input.get_axis("move_left", "move_right")
	
	if direction:
		velocity.x = direction * SPEED * delta
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED * delta)
	move_and_collide(velocity)

Both are CharacterBody2ds with movement mode set to flying

Also the Collision Mask is set so that only the ball collides with the paddle, if I change the collision so that the paddle has the ball on its mask another big problem appears, the ball can actually move the paddle out of position when it hits it on certain angles

Godot_v4.4.1-stable_mono_win64_DkFBxZfLgA

Stuck on this for the past few days and cant find the answer so any help is appreciated, thx!

The SPEED of ball and paddle are the same so they do travel in the same direction at the same speed, these limited physics are correct.

What you could add is a bounce for the paddle so it gets a little bounce and use a curve to control how fast it gets back to its original plane. That would give the ball enough for the ball to get a tiny bit of distance but ultimately they will travel in the same direction at the same speed. (How about massive cannon balls bouncing the paddle further than a feather ball, or a saw-blade ball cutting it in halves for a second. FUN!)

An alternative is to alter the rectangle collider box of the paddle and make it just a tiny bit wider at the bottom so the ball will always go up no matter what. This could also be done by clamping the velocity.x to (0.01, 1) but I think the collider box is easier to do and giving the paddle some bounce would make the game more fun.

You wouldn’t want the ball to go sideways in that situation. For starters, I would make the paddle quite a bit thicker.

Then put two Area2ds on it, both half the size one at the top half, one at the bottom half. And then code it so that if the ball hits the ‘top’ one the direction of the ball reflects upwards. When it hits the bottom one reflect it downwards.