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 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.

share|improve this question
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. – Martijn Courteaux 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. – Romeo 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. – Martijn Courteaux 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? – Romeo Apr 12 '12 at 10:11
I used something like 60. – Martijn Courteaux Apr 12 '12 at 10:12
up vote 3 down vote accepted

You are defining your bodies in pixels instead of meters. Box2D uses meters. This way, your bodies got a very very huge mass, which causes you having to apply to big forces / impulses.

You have to define the lengths in meters and upscale your scene when you draw it.

share|improve this answer
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); } ? – Romeo Apr 12 '12 at 10:38
@Romeo Start a new question. – doppelgreener Apr 12 '12 at 11:12

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.