物体相互穿过

时间:2017-08-21 08:25:11

标签: libgdx box2d

我有两个对象,一个是静态的,另一个是动态的。两个夹具都是从ChainShape创建的。问题是他们互相通过。

屏幕截图:

enter image description here

1 个答案:

答案 0 :(得分:0)

两个ChainShapes互不碰撞,使其中一个成为PolygonShape。 这对我有用:

BodyDef triangleDef = new BodyDef();
triangleDef.type = BodyDef.BodyType.DynamicBody;
triangleDef.position.set( 0, 0 );
Body triangleBody = this.world.createBody( triangleDef );
PolygonShape triangleShape = new PolygonShape();
triangleShape.set( new float[]{ 0, 0.5f, -0.5f, -0.5f, 0.5f, -0.5f } );
triangleBody.createFixture( triangleShape, 1 );
triangleShape.dispose();

BodyDef groundDef = new BodyDef();
triangleDef.position.set( 0, 0 );
Body groundBody = this.world.createBody( groundDef );
ChainShape groundShape = new ChainShape();
groundShape.createLoop( new float[]{ -10, 10, -10, -10, 10, -10, 10, 10 } );
groundBody.createFixture( groundShape, 1 );
groundShape.dispose();