Question

I have a problem with collision between 2 bodies(one dynamic and one static). Lets say that I have wall and ball, I set filter which allows the ball to pass through the wall. It works good as long as I create sprite with body outside the wall body. The problem appears when I create ball at the same position as wall then the ball gets stuck or bounce or does weird things. I believe that it shouldn't has matter where I create the body if there is collision filter. Had anyone similar problem ?

Was it helpful?

Solution 2

I still don't know why the problem appears but I know that it happens if I create boxBody and circleBody. I solved this problem using polygonBody instead of boxBody. Here is my code which create box from polygon body.

float a = this.getWidthScaled()*0.5f/32.0f;
float b = this.getHeightScaled()*0.5f/32.0f;
Vector2[] v = {new Vector2(-a,-b), 
               new Vector2(a,-b),
               new Vector2(a,b),
               new Vector2(-a,b)};
body = PhysicsFactory.createPolygonBody(pWorld, this, v, BodyType.DynamicBody, mFixtureDef);

OTHER TIPS

It's pretty late, but I got around a similar problem using masking

http://www.aurelienribon.com/blog/2011/07/box2d-tutorial-collision-filtering/

cheers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top