I'm creating a runner game, here is a screenshot : screenshot1
I divided my world in chunks, and i'm experiencing a collision issue. As you can see (in very small) on the bottom left, I have multiple grounds and they're moving to the left. Sometimes (by sometimes, I mean randomly) the runner bumps between two chunks and follows the ground to the left... screenshot2 (on the screenshot I placed the runner on the middle so I could take the screenshot)
I wrote a little fix to this but I find it very very [...] very dirty :
public void fixWeirdCollisionBug() {
body.setTransform(body.getPosition().x, body.getPosition().y + transformToScreen(0.0002f), body.getAngle());
}
I move the ground up (just a little) where is the runner to avoid this bug between two grounds. Actually I'm looking for a better way to do this...
I also have another problem. I want my runner to be able to jump with a positive x velocity so he will go forward on the ground. My ground is a kinematic body and my player is a dynamic body. I set the friction on the player to 0 so he stays on his initial state and doesn't 'follow' the ground. The thing is that I want the runner to go ahead and come back slowly to its initial state when he jumps.
I tried the following but it doesn't work, the runner keep sliding on the ground :
public void jump() {
if(!jumping) {
System.out.println("Jump !");
body.getFixtureList().get(0).setFriction(0.1f);
body.applyLinearImpulse(getUserData().getJumpingLinearImpulse(), body.getWorldCenter(), true);
jumping = true;
}
}
and when the runner is at its initial state :
if(body.getFixtureList().get(0).getFriction() != 0 && body.getPosition().x < Constants.RUNNER_X_DEFAULT) {
System.out.println("reset friction");
body.getFixtureList().get(0).setFriction(0);
body.setTransform(Constants.RUNNER_X_DEFAULT, body.getPosition().y, body.getAngle());
body.setLinearVelocity(0, 0); //also try to reset velocity to remove the sliding effect, but doesn't work
}
(this is in the act() method of the runner)
I hope that someone will find out what's wrong with my code because it's starting to give me a headache... Thank you very much
EDIT : I tried to use an HorizontalGroup to solve the random bumps : doesn't work