How to prevent CharacterBody2D from moving after collision with RigidBody2D

Godot Version

4.2

Question

The ball is RigidBody2D and the pad is CharacterBody2D, upon receiving the ball you can see the right pad move a little.
How to prevent the pad from moving but also keep the ball’s velocity?

Firstly, a RigidBody2D should not be able to move a CharacterBody2D. Secondly, is there any reason why you’re using a RigidBody2D here to begin with?

I’m very new to Godot so take everything I’m about to say with a grain of salt, but I would use an Area2D for the paddles. Otherwise, if you’re going to stick with the RigidBody2D, you could try turning down the mass of the ball in the inspector.

Use a StaticBody2D for your pads will solve your problem

1 Like

Nope, Area2D only detect if the ball is in its boundary, does not provide any collision info such as surface normal, so no.

Even at ball’s mass 0.01, result would be the same.

But if the ball only need to detect where it lands, such as the case of bullets, then Area2D is the best fit.

1 Like

You are right, move_and_slide() caused this.

Changing the paddle’s collision mask solved this.

Thanks for pointing out.

1 Like