Box2D takes collision response to an awesome level of realism where bodies act exactly as expected in most cases. However, there are a lot of situations within a game that demand custom collision dealing, such as receiving damage, controlling a ball, or simply pushing enemies.
After reading this recipe, you will easily be able to manage those special circumstances that will surely appear in your game.
The sample code will implement a balloon-breaker mini-game where a shuriken will follow your cursor looking for fragile balloons to destroy before they leave the scene dimensions.
You can find the code within the
Box2DCollisionReactionSample.java file. Remember to import sample projects.
In the next lines, ...