custom shape body not working

Hello. So I'm trying to create a custom shape that I define with points (b2Vec2) and then use the SetAsArray method to set it up (code below). So it creates it, but when a ball hits it, it's not working right. It seems like hitting quicksand and then falling through (I also set up boundaries so it hits that after it goes through, if I remove it then the ball just goes off screen). Here is the swf for you guys to see exactly what is happening (debug draw is on):

http://www.newgrounds.com/dump/item/81f3286a2e92393b919e5c90ca71cba3

And here is the code I'm using to create the shape (ignore the switch, it will always get the 1 case):

Code: Select all

var mToPx:Number = 20;
         var pxToM:Number = 1 / mToPx;
         
         var ar:Array;
         
         switch (num) {
            case 1:
               var v1:b2Vec2 = new b2Vec2(1 * pxToM, 500 * pxToM);
               var v2:b2Vec2 = new b2Vec2(200 * pxToM, 500 * pxToM);
               var v3:b2Vec2 = new b2Vec2(350 * pxToM, 400 * pxToM);
               var v4:b2Vec2 = new b2Vec2(270 * pxToM, 320 * pxToM);
               var v5:b2Vec2 = new b2Vec2(240 * pxToM, 360 * pxToM);
               var v6:b2Vec2 = new b2Vec2(195 * pxToM, 326 * pxToM);
               var v7:b2Vec2 = new b2Vec2(224 * pxToM, 292 * pxToM);
               var v8:b2Vec2 = new b2Vec2(151 * pxToM, 232 * pxToM);
               var v9:b2Vec2 = new b2Vec2(151 * pxToM, 200 * pxToM);
               var v10:b2Vec2 = new b2Vec2(110 * pxToM, 160 * pxToM);
               var v11:b2Vec2 = new b2Vec2(1 * pxToM, 160 * pxToM);
               
               ar = [v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11];
            default:
               ar [1];
         }
         
         var bd:b2BodyDef = new b2BodyDef();
         bd.position.Set(1 * pxToM, 1 * pxToM);
         bd.type = b2Body.b2_staticBody;
         
         var body:b2Body = world.CreateBody(bd);
         
         var ps:b2PolygonShape = new b2PolygonShape();
         ps.SetAsArray(ar);
         
         var fd:b2FixtureDef = new b2FixtureDef();
         fd.shape = ps;
         fd.density = 1;
         fd.friction = 0.3;
         
         body.CreateFixture(fd);
I also noticed this. It looks like a collision of arbitrary form only works for convex shapes. To simulate the concave shapes have to use composite convex shape.

Original thread: https://box2d.org/forum/viewtopic.php?t=8013