# Box2d Collision problem

I'm not good with words so here's a picture to describe my problem:

In my game there is this big ball which the user can move on x-axis only. Now, if the ball is falling like the red one, it's blast away. But, with the angle/hit position of the green one it's just kinda sliding on the big ball and falling.

I'm using Box2d above AndEngine on an Android platform.

What is the reason for my green ball problem?

• Just fyi, I've had the same issues in some of my projects which used Box2D. I was mostly able to workaround these cases by messing with the properties so that the shapes were almost exactly the same, but with slightly different values (say, perhaps a minimal unnoticable rotation of a square). Hope someone is able to answer this! – Philipp Lenssen May 29 '12 at 22:06
• I will sure try what you suggested. thank you dude – socksocket May 31 '12 at 19:28

Good image i can understand your problem much better from it. To solve this problem i would use some extra conditional statements(if you dont have them already). anyway here is how i would go about trying ti implement your project:

1. First the balls will need velocity(i assume you already have this).

2. The angle of incidence with the circle will need to be calculated when the collision happens.

3 you will need a conditional statement to tell the ball whether to trail along the outline(sorta like viscousity) or to bounce straight off. This condition is based on the incoming velocity and angle of incidence. If the ball is travelling slowly for example you will tell it to continue its path around the circle. However if the velocity is high enough and angle of incidence is also high you will resolve the new velocity based on incoming velocity and angle of incidence * some factor (if the circle is hard its(the factor) *1, soft * less than 1, bouncy * greater than 1).

It looks like your problem is with Restitution. Look at section 6.2 in the Manual. I'm not sure if AndEngine exposes this value but in libgdx, setting this property will give you the behavior you're looking for.

You could always register a custom ContactListener with your World. Create a class and implement the ContactListener interface, which containts 4 methods:

public void beginContact(Contact contact);
public void endContact(Contact contact);
public void preSolve(Contact contact, Manifold oldManifold);
public void postSolve(Contact contact, ContactImpulse impulse);


Then you can get a WorldManifold from the Contact that will tell you the normal of the two objects colliding. Filter out the collisions so that you know it's one ball colliding with another ball (I find the instanceof` keyword to be useful for this) and then apply some force in the opposite direction of the normal.

• The answer does not related to question. – Zhen Sep 29 '12 at 11:24
• @Zhen The answer is related to the question. It says: If you can't make it work, try this workaround. – MartinTeeVarga Jun 23 '13 at 9:25