How to fix weird behaviour in CharacterBody2D from velocity.bounce(...)?

Godot Version

4.7

Question

Hello! I’m currently remaking Ping Pong as my first game and I keep getting this weird issue where the ball isn’t getting reflected whenever it collides with a surface.

This is what it does instead:

And this is what I did for the code:

I checked the documentation and this seems to be the way to reflect vectors, so I’m really not sure what’s causing this issue.

You are setting velocity to Vector2(SPEED, SPEED), thereby overwriting the bounced velocity from previous collision. Don’t do that in _physics_process().

Thank you so much!! It works now!