Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using libgdx and its physic engine Box2d. My question is : how could I make my box2d body go through a block , ignore the first collison than make the block active so the ball can fall onto it. A good example is doodle jump.

enter image description here

share|improve this question

Set a flag whenever collisions are detected.

Something like this:

method Ball.onCollisionWith(block) {
    if (block == self.dontCollide) {
        self.dontCollide = block
        -- Do nothing else, passing through collision
    } else {
        -- Reset flag so next collision will pass again
        self.dontCollide = nil
        resolveCollision(self, block)

The Ball will then ignore every second collision due to its dontCollide flag being set.

share|improve this answer
If I'm not wrong this is C or C++, programming languages that I don't know and I don't have any chance to translate it into java/libgdx code :( could you please translate it ? – Ion Farima Mar 12 '13 at 14:19
It was only really pseudocode to begin with -- really just meant to illustrate a solution. I've converted it to look more like C though. Programming is a prerequisite for game programming. You should read an an introductory programming book. – Anko Mar 12 '13 at 17:30
I will consider your advice, thanks! :) – Ion Farima Mar 12 '13 at 18:16

I've had a similar problem in the past, have a look at this Tutorial. I found it answered my question. Its not for java but the code was very easy to copy over

share|improve this answer
Thanks, I'll take a look ! – Ion Farima Mar 12 '13 at 14:20
up vote 1 down vote accepted

I finally made it :)

Here's my code :

public void preSolve(Contact contact, Manifold oldManifold) {
        fixtureA = contact.getFixtureA();
        fixtureB = contact.getFixtureB();
          if(fixtureA.getBody().getUserData() == "platform" && fixtureB.getBody().getUserData() == "ball"|| fixtureA.getBody().getUserData() == "ball" && fixtureB.getBody().getUserData() == "platform"){
              if (fixtureA.getBody().getUserData() == "platform") { 
                  platform_y = fixtureA.getBody().getPosition().y;
                  ball_y = fixtureB.getBody().getPosition().y;
              } else if(fixtureA.getBody().getUserData() == "ball") {
                  ball_y = fixtureA.getBody().getPosition().y;
                  platform_y = fixtureB.getBody().getPosition().y;
                 if(ball_y < platform_y + 1.5F) {             //the ball is below

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.