0
votes


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 :)

1
@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 hereLiwaa
@Liwaa what is the value and type of these variable posx,posy , size , PPMAbhishek Aryan

1 Answers

1
votes

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