I'm making a Flash game, and I've encountered a really weird problem while trying to draw a polygonal shape in Box2D.
Here's the code I use:
var fixtureDefs:Array = new Array();
...
var fDef:b2FixtureDef = new b2FixtureDef();
fDef.density = 0;
fDef.shape = new b2PolygonShape();
b2PolygonShape(fDef.shape).SetAsArray(vertexArray);
fixtureDefs.push(fDef);
//This gets repeated several times, so that at the end you get a body consisting of several convex shapes.
...
var bD:b2BodyDef = new b2BodyDef();
bD.type = b2Body.b2_staticBody;
bD.position.Set(300/Constants.RATIO,200/Constants.RATIO);
var body:b2Body = Constants.world.CreateBody(bD);
...
for each(var fD:b2FixtureDef in fixtureDefs) {
body.CreateFixture(fD);
}
Where vertexArray is a valid array containing 4 b2Vec2 vertices, making up a convex shape.
The problem is, when I test, collisions don't work right for that body. Most other objects -enemies, user-controlled characters - pass straight through, as if the body isn't there at all. Some raycasts pass through as well.
Infuriatingly enough, one kind of bodies I have (a custom enemy) somehow does detect the body and collides with it. The raycasts that particular kind of enemy attempts do work - when your character hides behind the polygon, it's like they can't see him.
The other weird thing: when I try the same code, only go for SetAsBox instead of SetAsArray, it works exactly as it should.
I'm using a custom ContactListener class, but I haven't done any contact filtering (unless it's possible to do that without realising).
I'm using the Flash 9 version of Box2D 2.1a.
Any suggestions? Am I missing something obvious or have I (God forbid!) discovered a bug? Thanks for your help!
Andrey