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 :

    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;

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 !

  • \$\begingroup\$ I think what you want to do is set your Body isKinematic to true. \$\endgroup\$ – jgallant Jul 21 '15 at 18:48
  • \$\begingroup\$ What @Jon said except in Libgdx you want bodyDef.type = BodyType.KinematicBody. \$\endgroup\$ – XiaoChuan Yu Jul 21 '15 at 19:40
  • \$\begingroup\$ Now that my BodyType is KinematicBody, they doesn't even collide. Plus they don't collide against walls :/ \$\endgroup\$ – Kamigaku Jul 21 '15 at 20:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.