Greg
Greg

Reputation: 1152

AndEngine and box2d collision filtering

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 ?

Upvotes: 1

Views: 1485

Answers (2)

Greg
Greg

Reputation: 1152

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);

Upvotes: 0

Mike Opshinsky
Mike Opshinsky

Reputation: 33

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.

Upvotes: 2

Related Questions