b2Body through customShape, why?

Hi,
I´m doing my first Box2D game, and today I found a weird problem (at least for me, I´m a noob).

I have a body (with a Sprite attached, a pig ;D) that falls to the ground, everything normal... but it passes through the custom shape (wich takes part of a b2RevoluteJoint with the sphere).

It´s like if the custom shape were an "invisible shape" in the long shape, but if the body hits the "fat part" of the custom shape acts normal, rebounds totally normal...

Can anyone explain me why this happens? I don´t understand it... Thanks!

Image
Your custom shape is concave, how did you make it?
Try drawing everything with debug draw so you can see exactly what box2d sees.
Thanks for the answer!

well, I made the shape defining an array containing a b2Vec in each element and creating a b2PolygonShape and setting it as array

Code:
var myPS:b2PolygonShape = new b2PolygonShape();
myPS.setAsArray(myArray, vertexCount);


Something similar to this code above (plus de array and the verterCount, of course).

So, I can´t made a shape like this one? Must I made a joint with two boxes and then another joint with this joint and the sphere? I don´t know if this is possible 🙂 What would you made in this case?
in your case the body should consist of 2 rectangle shapes.
actually it's not just your case it has to do with the way the engine works. it can't handle concave shapes and it's you responsibility to break down such shapes into multiple convex shapes to get it to work.
Ups, I never saw this... can I made a body with two shapes? I didn´t know it 😕

How must I do that?
take a look at this blog post - http://www.emanueleferonato.com/2008/12/12/the-magic-of-compound-objects-with-box2d/
in this case the body consist of many box shapes. those shapes might as well be custom polygons which you supplied the vertices coordinates for. but you should note that even in this case those point need to form concave shape.
if one or many shapes in your compound body is not concave then the results are unpredictable.
there are some useful jsfl scripts and extensions which will help you decompose convex shapes (actual shapes drawn in flash) into set of coordinates to use in your code. just do a search for 'polygon decomposition', 'triangulation' in the forum and lots of results will pop up.
Ok, really really thanks!

I´ll try it later at home 🙂

Thanks vitaLee, thank you very much.
hi again vitaLee, I did it but I still have a problem... I used this code

Code:
 
            //PART I DEFINING THE BODY
            //
            var elMartillo:b2Body;           
            var martilloBD:b2BodyDef = new b2BodyDef();
            elMartillo = main.mundo.CreateBody(martilloBD);
            //
            //PART 2 CREATING THE FIRST PART
            //     
            var martilloPS:b2PolygonShape = new b2PolygonShape();
            martilloPS.SetAsBox(20 / main.ratio, 80 / main.ratio);
               
            var martilloF:b2FixtureDef = new b2FixtureDef();
            martilloF.shape = martilloPS;
            martilloF.density = 10;
               
            martilloBD.position.Set(posX, posY+(160/main.ratio));
            martilloBD.type = b2Body.b2_dynamicBody;

            elMartillo = main.mundo.CreateBody(martilloBD);
            elMartillo.CreateFixture(martilloF);
            //
            //PART 3 CREATING THE SECOND PART
            //           
            var martillo2PS:b2PolygonShape = new b2PolygonShape();
            martillo2PS.SetAsBox(50 / main.ratio, 30 / main.ratio);
               
            var martillo2F:b2FixtureDef = new b2FixtureDef();
            martillo2F.shape = martillo2PS;
            martillo2F.density = 2;
               
            //var martillo2BD:b2BodyDef = new b2BodyDef();
            martilloBD.position.Set(posX, posY+(180/main.ratio));
            martilloBD.type = b2Body.b2_dynamicBody;

       elMartillo = main.mundo.CreateBody(martilloBD);
            elMartillo.CreateFixture(martillo2F);
           



I create the two parts of the body, but they´re not attached, they seem like two different bodies... do you know what I´m doing wrong? I´m looking the code but I don´t know where´s the mistake...
you're creating two bodies
elMartillo = main.mundo.CreateBody(martilloBD);
and calling CreateFixture(martillo2F) on 2 different instances of b2Body that's why you get 2 bodies.
what you need is just one body and createFixtures for every shape you need.
here's a short snippet of the class i created - http://pastebin.com/wB4D4y3Q
Code:
bodyDef = new b2BodyDef();
bodyDef.position.Set(mouseX / _worldScale, mouseY / _worldScale);
bodyDef.type = b2Body.b2_dynamicBody;
         
boxDef = new b2PolygonShape();
body = _world.CreateBody(bodyDef);
         
var fd:b2FixtureDef = new b2FixtureDef();
fd.shape = boxDef;
fd.density = 2.0;
boxDef.SetAsBox(30 / _worldScale, 2 / _worldScale);
body.CreateFixture(fd);
boxDef.SetAsBox(2 / _worldScale, 30 / _worldScale);
body.CreateFixture(fd);
Thanks VitaLee, you solved my problem and the most important, you explained it carefully, you´re a fucking present from the Gods!!!

Thanks again 🙂

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