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.
Answer
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
contact.setEnabled(false);
}
}
}
No comments:
Post a Comment