# Box2D No Gravity when moving against wall

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);

body.setLinearVelocity(linearMovement);
}


and

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


movespeed is 8

• Usually you should not set the Bodys velocity, but you should add a force or impulse instead. Jun 8, 2015 at 7:26

## What's Happening

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

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.

## x-Momentum

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

## y-Momentum

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

## 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:

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)

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.

## Case 2 (what you want)

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:

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

• 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! Jun 11, 2015 at 18:33
• 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. Jun 12, 2015 at 4:16
• This is just fine and I understand it :) Jun 12, 2015 at 15:47