Dynamic bodies collision

Discuss issues specific the Java port of Box2D
Kamigaku
Posts: 1
Joined: Wed Jul 22, 2015 10:11 am

Dynamic bodies collision

Postby Kamigaku » Wed Jul 22, 2015 12:46 pm

Hi,

I'm implementing Box2D for my 2d top down LIBGDX game and i have some struggle with two dynamic body. Currently, my two bodies are created that way :

Code: Select all

    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DynamicBody;
    bodyDef.position.set(this.x, this.y);
    this.body = world.createBody(bodyDef);
    PolygonShape collider = new PolygonShape(); 
    collider.setAsBox(16, 16);
    FixtureDef fDef = new FixtureDef();
    fDef.density = 0f;
    fDef.friction = 0f;
    fDef.restitution = 0f;
    fDef.shape = collider;
    body.createFixture(fDef);
    body.setUserData(this);
    collider.dispose();


Here is what happen when my 2 players collide : http://gfycat.com/InnocentHotAracari

So basicly, no rotation, no friction and no restitution. Also, my world have a gravity of 0 (since it's a 2d top down game, i don't that want them to fall). When player 1 collide with player 2, player 2 is moved backward like it was push but i don't want that. I want it to stay where he is, blocking the path to player 1 but he can also move.

Is there a way to do that ? I have looked for some tips like catching collision with the contact listener but i don't know what to do in the preSolve method.

I'd like some help, thanks !

Return to “Java”



Who is online

Users browsing this forum: No registered users and 1 guest