I have several balls in a world that collide with each other. There are static walls on all sides of the world.
Sometimes, they end up in a position where they keep on moving up/down or left/right along the same path (motion perpendicular to the wall?)
Is there any easy way to detect this, and then, apply a little rotation to it on either direction?
Pseudocode or code in any language that has box2d would be appreciated.
Edit: Image, as requested by @Andrew

If the ball keeps moving like this (left/right/left/right…), I want to give it a little push so it moves from the current path.
I think you can create your
b2ContactListenersubclass to detectball-wallcollisions (It is simple and explained inBox2D manual). After you made it store 3 velocity values for each of your balls.ball-wallcollision.ball-wallcollision.ball-wallcollision.When you obtained these three velocities (use
GetLinearVelocityfunction ofb2Body) – check if they lie on the same line with some precision (have the same direction except the sign). If this condition is satisfied – apply a little rotation