I'm coding a game with Flutter and the flame_forge2d package (which uses Box2D internally). I want to make a game whose principle is similar to that of the game One More Bounce (a game where you have to move a ball forward by placing bars on which the ball bounces).
In One More Bounce, the player controls a ball that ALWAYS bounces (no matter the forces applied). The advantage of such behavior is that the ball never gets stuck in a corner (which would be bad since the aim of the game is precisely to make the ball bounce by placing paddles at the bottom). I would like to have the same behavior but everything I have tested so far does not allow the ball to bounce in all situations. I don't know if the One More Bounce developers used Box2D or a custom collision system. Anyway, I would like to have the same behavior!
When the ball hits another object, this is what I do (that does not prevent the ball from stopping) :
@override
void endContact(Object other, Contact contact) {
super.endContact(other, contact);
final linearVelocity = body.linearVelocity.clone();
final length = linearVelocity.normalize();
if (length < 1) {
body.linearVelocity = linearVelocity * 1;
}
}
If you have any ideas on how to do this (or if we literally need to change the basic behavior of the ball), I'm all ears.