2
votes

im stuck with something here.

Ive been trying to create a polygon shape with Libgdx and the in built Box2d classes. my codes are the following. I create 8 vectors in an array and draw the object. the polygone shape starts at (82,0) of world coordinates.

            Vector2[] vertices = new Vector2[8];

    vertices[0] = new Vector2(82f  , 0f  );
    vertices[1] = new Vector2(146f , 40f  );
    vertices[2] = new Vector2(385f , 268f);
    vertices[3] = new Vector2(322f , 341f);
    vertices[4] = new Vector2(225f , 322f);
    vertices[5] = new Vector2(282f , 398f);     
    vertices[6] = new Vector2(161f , 457f);
    vertices[7] = new Vector2(135f , 298f);
    PolygonShape shape = new PolygonShape();
    shape.set(vertices);

the shape im getting is this:screenshot of object

and thats fine, but the circle shape cant detect any collision on the sides of that object ?!?!!

any tips ?

3

3 Answers

2
votes

For a start your vectors are using values which are enormous in terms of what Box2D normally works with.

http://box2d.org/2011/12/pixels/

Try scaling things down and using a world-to-screen conversion i.e.

http://www.box2d.org/forum/viewtopic.php?f=3&t=8198

2
votes

Apply same group index to each shape in the world fixtureDef.filter.groupIndex = 0;

0
votes

The reason is your shape is concave i.e. it has a cut into it. Box2d only detects collisions with convex polygons.