0


Im working with Box2D on LibGDX, and I'm working with bodies and collisions etc..
HERE, i had the problem of a body colliding with another, when it shouldn't do that.
Now after Knowing that i need to use ChainShapes, i started with that.
Whenever u run my project, i get an assertion error:

Assertion failed: (count >= 2), function CreateChain, file /Users/tom/Coding/slave/workspace/libgdx-mac/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2ChainShape.cpp, line 62.


So i tried a small debug to print the vertex count, and the vertex out printed as 0.
Problem is that i am adding the vertices and they dont appear to be added...
Code for adding verticies:

    chain = new ChainShape();
    chain.setNextVertex(new Vector2((posx - size) / PPM, (posy + size) / PPM));
    chain.setNextVertex(new Vector2((posx + size) / PPM, (posy + size) / PPM));
    chain.setNextVertex(new Vector2((posx + size) / PPM, (posy - size) / PPM));
    chain.setNextVertex(new Vector2((posx - size) / PPM, (posy - size) / PPM));
    System.out.println(chain.getVertexCount());


Vertex count is printed as 0, thats why i am getting the error, I dont know how to fix it, so please help :)

Liwaa
  • 35
  • 9
  • Would this help? (not tested) https://stackoverflow.com/questions/35381381/chainshape-in-box2d/35668026 – javaLover Jun 01 '17 at 10:16
  • @javaLover I tried that, and i am still achieving the same error, i actually searched a lot, but found nothing useful, thats why i posted here – Liwaa Jun 01 '17 at 10:57
  • @Liwaa what is the value and type of these variable `posx`,`posy` , `size` , `PPM` – Abhishek Aryan Jun 01 '17 at 13:19

1 Answers1

1

Create your ChainShape in this way :

ChainShape chain=new ChainShape();

Vector2 vector[]=new Vector2[4];
vector[0]=new Vector2((posx - size) / PPM, (posy + size) / PPM);
vector[1]=new Vector2((posx + size) / PPM, (posy + size) / PPM);
vector[2]=new Vector2((posx + size) / PPM, (posy - size) / PPM);
vector[3]=new Vector2((posx - size) / PPM, (posy - size) / PPM);

chain.createChain(vector);

System.out.println(chain.getVertexCount());  // 4 on console

If still you've problem, check the value of posx, posy, size , PPM

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65