# Box2D platformer movement. Should i mess with velocity?

I have a platformer game in which I implemented the movement using a wheel attached to the hero. For jumping I use this:

player.body.applyLinearImpulse(new Vec2(0, 30000000), player.body.getPosition());


The problem is that the xVelocity doesn't remain the same during the jump so it isn't looking natural. Is there any way to modify only the x velocity of the body so that before jumping I store it in a variable and after jumping I apply it to the body?

I hope you understand what I am trying to say.

• That behaviour looks pretty uncommon. Also your impulse is enormous. In my game, the impulse I used for jumping was literally 1. Try figuring out what is wrong with your Box2D world. Apr 12 '12 at 9:32
• Well, i created the world with the gravity Vector2(0, -10). And for my human i have 2 bodies both with 1f density. I don't know why but a smaller impulse wont move the body. It seemed pretty weird to me too but i didn't know what to do. Apr 12 '12 at 10:02
• I think that you are creating your bodies with the size of pixels... Box2D works in meters. You have to scale the scene when you render the it. Apr 12 '12 at 10:04
• That's exaclty what i was doing. Can you please tell me a good ratio pixel to meter? Or is there a standard? Apr 12 '12 at 10:11
• I used something like 60. Apr 12 '12 at 10:12

• Also if you can help me a little bit. I defined my PIXEL_TO_METER = 60f. How do i need to modify these 2 functions: public Vec2 screenToWorld(Vec2 screenV) { return new Vec2(screenV.x + this.x, yFlip * screenV.y + this.y ); } and public Vec2 worldToScreen(Vec2 worldV) { return new Vec2(worldV.x - this.x, yFlip * worldV.y - this.y); } ? Apr 12 '12 at 10:38