I use Box2D in my current project and I have a problem with the gravity..

You can see my problem here: https://www.youtube.com/watch?v=2_kv9LkKwN4&feature=youtu.be

when i jump normal everything is fine, but when I press against a wall while I jump the body doesn't fall down after I release the move key in the direction of the wall the body falls down.

This is my move code:

public void moveByLinear(float x, float y) {
    linearMovement.set(x, y);



moveByLinear(movespeed, getBody().getLinearVelocity().y);

movespeed is 8

  • \$\begingroup\$ Usually you should not set the Bodys velocity, but you should add a force or impulse instead. \$\endgroup\$
    – Robert P
    Jun 8, 2015 at 7:26

1 Answer 1


What's Happening

This is completely accurate physical behaviour, which can be explained using a free-body diagram and a little high school physics1:

enter image description here

The mass of the block is m and g is the gravitational constant. Fa is the applied force. To understand why the block is not moving, we can write out the force balances in the x and y directions.


I will assume that the block is not accelerating in this direction, as in the video. enter image description here


For the time being I will assume nothing about the acceleration in the y direction, so the parameter ay remains in the equation.

enter image description here

Friction Force

The friction force, being a reactive force, is bound by a set of rules, depending on a number of factors. The first rule is that the magnitude of the force is limited by the inequality:

enter image description here

where the greek letter mu (I pronounce it like the name of pokemon #151) is the coefficient of friction and Fn is the normal force. The right hand side of this equation is an upper-limit on the friction force.

Friction only resists relative motion between the surfaces in contact. When these surfaces are not moving relative to one another, the friction force vector opposes the sum of any other forces acting along the contact surface.

On the other hand, when there is relative motion at the surface the friction force opposes the direction of motion.

Given the inequality, there are two possible cases for the motion of the block. In both cases I will assume the block starts from rest.

Case 1 (current situation)

enter image description here

In this case, the friction force will oppose the only other force acting along the contact surface (the gravity force) so that the acceleration is zero.

enter image description here

Case 2 (what you want)

enter image description here

In this case the surface responds with the largest possible friction force, Ff,max, which is not enough to prevent the block from accelerating downward:

enter image description here

Recommended Solution

If you want the block to fall, the easiest way to do so is to set the friction of the fixturedefs of the fixtures in contact to 0. This should guarantee that the maximum friction force is 0, because mu is zero.

1Note that what I presented is not entirely accurate, but simplified for present understanding. In real life there is a non-uniform distributed load across the contact surface such that the moment of the friction force is balanced by a greater reaction force at the lower part of the contact surface. In box2d this is approximated by splitting the normal force into just two (un-equal) point forces which counteract the torque from the friction force at the two vertices in contact.

  • \$\begingroup\$ Ok, I think I didn't undertood everything correctly but I think I know what you mean because english isn't my native language.......... So thank you very much, now it works! \$\endgroup\$
    – Richard H
    Jun 11, 2015 at 18:33
  • \$\begingroup\$ If you want me to explain anything in more detail or using more simple language let me know. If you're happy with it please consider accepting my answer by clicking the green checkmark beside the answer. \$\endgroup\$ Jun 12, 2015 at 4:16
  • \$\begingroup\$ This is just fine and I understand it :) \$\endgroup\$
    – Richard H
    Jun 12, 2015 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .