Get a Rigidbody2D ball to bounce only when collider is perpendicular

Godot Version

4.2

Question

I’m using RigidBody2D on a ball moving at a constant speed. I want this ball to always slide on walls (such as if the physics_material_override’s bounce parameter was set to 0), excepted if the colliding wall is perpendicular, in this case I want it to basically bounce (such as if the physics_material_override’s bounce parameter was set to 1). but it seems I can only get one of those two behaviors, either sliding or bouncing on everything. What would be the best way to achieve my goal?

Do you really need a Rigidbody for this behavior?

It will be easier to code this behaviour with a Character body

Thanks @Exerion and @FreakyGoose for your answers. I first gave a try with CharacterBody, but I got weird sliding reactions with it.

The Solution I came with was using A Rigidbody2D, add a RayCast as a child, which will detect the collision before it happens, and if the collision normal has a perpendicular angle, modify the behavior of the Physics_material override.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.