java - Bodies not colliding properly in Box2D(LibGDX) -
so, in game have box2d dynamic body polygon shape player , box2d static body chain shape static box. debug renderer showing boxes correctly. when player collides box top, collides, when either side, goes right trough. have tried use polygons static boxes, acts weirdly. can't figure out what's wrong.
here code:
player body , fixture definition:
bdef=new bodydef(); bdef.position.set((width/2+169)/ppm,100/ppm); bdef.type=bodytype.dynamicbody; body=world.createbody(bdef); polygonshape shape=new polygonshape(); shape.setasbox(16/ppm,16/ppm); fdef=new fixturedef(); fdef.shape=shape; fdef.filter.categorybits=b2dvars.bit_player; fdef.filter.maskbits=b2dvars.bit_block; body.createfixture(fdef).setuserdata("player");
static box body , fixture definition:
bdef=new bodydef(); fdef=new fixturedef(); bdef.type=bodytype.staticbody; bdef.position.set((col+0.5f)*tilesize/ppm,(row+0.5f)*tilesize/ppm); chainshape chainshape=new chainshape(); vector2[] v=new vector2[5]; v[0]=new vector2(-tilesize/2/ppm,-tilesize/2/ppm); v[1]=new vector2(tilesize/2/ppm,-tilesize/2/ppm); v[2]=new vector2(tilesize/2/ppm,tilesize/2/ppm); v[3]=new vector2(-tilesize/2/ppm,tilesize/2/ppm); v[4]=new vector2(-tilesize/2/ppm,-tilesize/2/ppm); chainshape.createchain(v); fdef.friction=0; fdef.shape=chainshape; fdef.issensor=false; fdef.filter.categorybits=b2dvars.bit_block; fdef.filter.maskbits=b2dvars.bit_player; world.createbody(bdef).createfixture(fdef).setuserdata("block");
edit: problem no more, problem me setting player position transforming, don't know, how else make player move when push button , stop when release it?
moving dynamicbody
should not done via settransform
. smoothest way set dynamicbody
position via mousejoint
, whether or not it'll depends on kind of movement after. example excellent place start.
Comments
Post a Comment