# Mario like jumping and landing in box2d, help

I've been trying to get Mario type jumping/landing in a Box2d game and it's been giving me some trouble.

Results: Player loses velocity on landing

Desired Results: When player lands it will continue at the same velocity it was in the air.

 Player loses velocity on impact, but quickly regains its set max speed.

I know this is an issue with friction and I've tried setting the friction to 0 when the user is pressing Left and Right movement keys and back to normal friction when the player is not pressing those keys. This however, does not work as the state does not get changed until the collision is over and the player will be stuck sliding until the collision state has changed.

My next best guess is to set friction to zero all together for the player and simulating an opposing force on the player.

Solution? Tips? Heck... maybe there's a tutorial out there I missed.

        Vector2 a = entityBody.getLinearVelocity();
float force = 0;

if(Gdx.input.isKeyPressed(Keys.D)){
if(a.x < 5) force = 25;
//entityBody.getFixtureList().get(0).setFriction(0);
//floor.entityBody.getFixtureList().get(0).setFriction(0);
//entityBody.resetMassData();

//entityBody.applyLinearImpulse(new Vector2(0f,1f), entityBody.getWorldCenter());
//entityBody.applyForce(new Vector2(0f,50f), entityBody.getWorldCenter());
}
else if(Gdx.input.isKeyPressed(Keys.A)){
if(a.x > -5) force = -25;
//entityBody.getFixtureList().get(0).setFriction(0);
//floor.entityBody.getFixtureList().get(0).setFriction(0);
//entityBody.resetMassData();

//entityBody.applyForce(new Vector2(0f,50f), entityBody.getWorldCenter());
}
else{
entityBody.getFixtureList().get(0).setFriction(.4f);
floor.entityBody.getFixtureList().get(0).setFriction(.4f);
}

if(Gdx.input.isKeyPressed(Keys.W)){
a.y = 5;
entityBody.setLinearVelocity(a);
}

entityBody.applyForce(new Vector2(force, 0), entityBody.getWorldCenter());

• For what it's worth, making a mario-like jump in a 2D physics engine is a total nightmare. It's possible, but a true struggle to make it feel right, because the truth is, Mario's jumps weren't physically "real" at all. Higher jumps when you hold down longer while in-air, steering while in-air, etc. – Cameron Fredman Mar 8 '13 at 2:54
• haha, tell me about it :) ... but minus the player movement, which I want to have strict control over, the rest of the game will be physics based. – mjrevel Mar 8 '13 at 3:30
• I don't know about Box2D, but some physics engines have the concept of a "kinematic" rigid body which is something that you control directly that interacts with the rest of the physics world. So you could control movement directly but still have it somewhat work with the physics engine. – Tetrad Mar 8 '13 at 17:13
• Yes try kinematic... – Mikael Högström Mar 18 '13 at 22:16