Body not moving

I am using Box2DX (C#) to create a simple test in my game that involves nothing more than a circle body and the gravity field.

But for some reason the body refuses to start moving, I have checked that I am calling world.Step, but I can't see what the problem is.

I had the same problem when trying to use Physics2D.Net, which caused me to try Box2DX.
You should provide some more information, otherwise it's very difficult to diagnose the problem.

Are you setting the mass of the object?

Bill
Yeah Im using the mass from shape function. I'm more or less following the Hello World tutorial, but with a circle and no ground plane.
Is the world rect too small?
the2bears wrote:
You should provide some more information, otherwise it's very difficult to diagnose the problem.


I'll quote myself for truth here. Seriously, best to show some code. Otherwise it's a guessing game and no one wants to play that, right? 😉

Bill
Try to get your body mass, it must be bigger than 0. (Maybe you are trying to move world's ground body, it is automatically created with the world)
Are you sure about your World.Step ? Maybe your timestep is wrong? Or maybe you are calling it only once?
What about your circle shape? Do you set any density for it?
Do you call body.SetMassFromShapes ?
What about your gravity vector?
Maybe your bounding box is too small?
I'm having the same problem, but I'm using pybox2d.
I'm currently writing an engine, and the dynamic bodies I created weren't affected by gravity unless I increased the mass by at least 10x of what I wanted. In addition, the dynamic shapes weren't colliding with static shapes or each other at all.

This was very annoying since I had gotten tests to work previously and all of a sudden it just stopped working.

I got very frustrated by this and basically recreated Hello.py to see if I could get that to work. Here's the code, which is essentially the same thing I'm doing in the engine:

Code:
import Box2D as box2d

worldAABB = box2d.b2AABB()
worldAABB.lowerBounds = (-100, -100)
worldAABB.upperBounds = (100, 100)

gravity = box2d.b2Vec2(0, -10)
doSleep = True

world = box2d.b2World(worldAABB,gravity, doSleep)

gd = box2d.b2BodyDef()
gd.position = (0, 10)
g = world.CreateBody(gd)

gs = box2d.b2PolygonDef()
gs.SetAsBox(50, 10)
g.CreateShape(gs)

bd = box2d.b2BodyDef()
bd.position = (0, 30)
body = world.CreateBody(bd)

bs = box2d.b2PolygonDef()
bs.SetAsBox(1, 1)
bs.density = 1
bs.friction = 0.3
body_shape = body.CreateShape(bs)
body.SetMassFromShapes()

for i in range(0, 300):
    world.Step(1.0/60.0, 10, 8)
    print body.GetPosition()


The body moved a tiny bit at first, then stopped. Here's the output I got:

Quote:
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
b2Vec2(0,29.9972)
...


If I change the dimensions of the body's shape:

Code:
bs = box2d.b2PolygonDef()
bs.SetAsBox(100, 100)
bs.density = 1
bs.friction = 0.3
body_shape = body.CreateShape(bs)
body.SetMassFromShapes()


I get this output:

Quote:
b2Vec2(0,29.9972)
b2Vec2(0,29.9917)
b2Vec2(0,29.9833)
b2Vec2(0,29.9722)
b2Vec2(0,29.9583)
b2Vec2(0,29.9417)
b2Vec2(0,29.9222)
b2Vec2(0,29.9)
b2Vec2(0,29.875)
b2Vec2(0,29.8472)
b2Vec2(0,29.8167)
b2Vec2(0,29.7833)
b2Vec2(0,29.7472)
b2Vec2(0,29.7083)
b2Vec2(0,29.6667)
b2Vec2(0,29.6222)
b2Vec2(0,29.575)
b2Vec2(0,29.525)
b2Vec2(0,29.4722)
b2Vec2(0,29.4167)
b2Vec2(0,29.3583)
b2Vec2(0,29.2972)
b2Vec2(0,29.2333)
b2Vec2(0,29.1667)
b2Vec2(0,29.0972)
b2Vec2(0,29.025)
b2Vec2(0,28.95)
b2Vec2(0,28.8722)
b2Vec2(0,28.7917)
b2Vec2(0,28.7083)
b2Vec2(0,28.6222)
b2Vec2(0,28.5333)
b2Vec2(0,28.4417)
b2Vec2(0,28.3472)
b2Vec2(0,28.25)
b2Vec2(0,28.15)
b2Vec2(0,28.0472)
b2Vec2(0,27.9417)
b2Vec2(0,27.8333)
b2Vec2(0,27.7222)
b2Vec2(0,27.6083)
b2Vec2(0,27.4917)
b2Vec2(0,27.3722)
b2Vec2(0,27.25)
b2Vec2(0,27.125)
b2Vec2(0,26.9972)
b2Vec2(0,26.8667)
b2Vec2(0,26.7333)
b2Vec2(0,26.5972)
b2Vec2(0,26.4583)
b2Vec2(0,26.3167)
b2Vec2(0,26.1722)
b2Vec2(0,26.025)
b2Vec2(0,25.875)
b2Vec2(0,25.7222)
b2Vec2(0,25.5667)
b2Vec2(0,25.4083)
b2Vec2(0,25.2472)
b2Vec2(0,25.0833)
b2Vec2(0,24.9167)
b2Vec2(0,24.7472)
b2Vec2(0,24.575)
b2Vec2(0,24.4)
b2Vec2(0,24.2222)
b2Vec2(0,24.0417)
b2Vec2(0,23.8583)
b2Vec2(0,23.6722)
b2Vec2(0,23.4833)
b2Vec2(0,23.2917)
b2Vec2(0,23.0972)
b2Vec2(0,22.9)
b2Vec2(0,22.7)
b2Vec2(0,22.4972)
b2Vec2(0,22.2917)
b2Vec2(0,22.0833)
b2Vec2(0,21.8722)
b2Vec2(0,21.6583)
b2Vec2(0,21.4417)
b2Vec2(0,21.2222)
b2Vec2(0,21)
b2Vec2(0,20.775)
b2Vec2(0,20.5472)
b2Vec2(0,20.3167)
b2Vec2(0,20.0833)
b2Vec2(0,19.8472)
b2Vec2(0,19.6083)
b2Vec2(0,19.3667)
b2Vec2(0,19.1222)
b2Vec2(0,18.875)
b2Vec2(0,18.625)
b2Vec2(0,18.3722)
b2Vec2(0,18.1167)
b2Vec2(0,17.8583)
b2Vec2(0,17.5972)
b2Vec2(0,17.3333)
b2Vec2(0,17.0667)
b2Vec2(0,16.7972)
b2Vec2(0,16.525)
b2Vec2(0,16.25)
b2Vec2(0,15.9722)
b2Vec2(0,15.6917)
b2Vec2(0,15.4083)
b2Vec2(0,15.1222)
b2Vec2(0,14.8333)
b2Vec2(0,14.5417)
b2Vec2(0,14.2472)
b2Vec2(0,13.95)
b2Vec2(0,13.65)
b2Vec2(0,13.3472)
b2Vec2(0,13.0417)
b2Vec2(0,12.7333)
b2Vec2(0,12.4222)
b2Vec2(0,12.1083)
b2Vec2(0,11.7917)
b2Vec2(0,11.4722)
b2Vec2(0,11.15)
b2Vec2(0,10.825)
b2Vec2(0,10.4972)
b2Vec2(0,10.1667)
b2Vec2(0,9.83333)
b2Vec2(0,9.49722)
b2Vec2(0,9.15833)
b2Vec2(0,8.81666)
b2Vec2(0,8.47222)
b2Vec2(0,8.125)
b2Vec2(0,7.775)
b2Vec2(0,7.42222)
b2Vec2(0,7.06667)
b2Vec2(0,6.70833)
b2Vec2(0,6.34722)
b2Vec2(0,5.98333)
b2Vec2(0,5.61667)
b2Vec2(0,5.24722)
b2Vec2(0,4.875)
b2Vec2(0,4.5)
b2Vec2(0,4.12222)
b2Vec2(0,3.74167)
b2Vec2(0,3.35833)
b2Vec2(0,2.97222)
b2Vec2(0,2.58333)
b2Vec2(0,2.19167)
b2Vec2(0,1.79722)
b2Vec2(0,1.4)
b2Vec2(0,1)
b2Vec2(0,0.597224)
b2Vec2(0,0.191669)
b2Vec2(0,-0.216664)
b2Vec2(0,-0.627775)
b2Vec2(0,-1.04166)
b2Vec2(0,-1.45833)
b2Vec2(0,-1.87777)
b2Vec2(0,-2.3)
b2Vec2(0,-2.72499)


As you can see, it just flies right past the ground body. And if you set the dimensions to slightly lower:

Code:
bs = box2d.b2PolygonDef()
bs.SetAsBox(45, 45)
bs.density = 1
bs.friction = 0.3
body_shape = body.CreateShape(bs)
body.SetMassFromShapes()


the body just stops moving completely after a while:

Quote:
b2Vec2(0,29.9972)
b2Vec2(0,29.9917)
b2Vec2(0,29.9833)
b2Vec2(0,29.9722)
b2Vec2(0,29.9583)
b2Vec2(0,29.9417)
b2Vec2(0,29.9222)
b2Vec2(0,29.9)
b2Vec2(0,29.875)
b2Vec2(0,29.8472)
b2Vec2(0,29.8167)
b2Vec2(0,29.7833)
b2Vec2(0,29.7472)
b2Vec2(0,29.7083)
b2Vec2(0,29.6667)
b2Vec2(0,29.6222)
b2Vec2(0,29.575)
b2Vec2(0,29.525)
b2Vec2(0,29.4722)
b2Vec2(0,29.4167)
b2Vec2(0,29.3583)
b2Vec2(0,29.2972)
b2Vec2(0,29.2333)
b2Vec2(0,29.1667)
b2Vec2(0,29.0972)
b2Vec2(0,29.025)
b2Vec2(0,28.95)
b2Vec2(0,28.8722)
b2Vec2(0,28.7917)
b2Vec2(0,28.7083)
b2Vec2(0,28.6222)
b2Vec2(0,28.5333)
b2Vec2(0,28.4417)
b2Vec2(0,28.3472)
b2Vec2(0,28.25)
b2Vec2(0,28.15)
b2Vec2(0,28.0472)
b2Vec2(0,27.9417)
b2Vec2(0,27.8333)
b2Vec2(0,27.7222)
b2Vec2(0,27.6083)
b2Vec2(0,27.4917)
b2Vec2(0,27.3722)
b2Vec2(0,27.25)
b2Vec2(0,27.125)
b2Vec2(0,26.9972)
b2Vec2(0,26.8667)
b2Vec2(0,26.7333)
b2Vec2(0,26.5972)
b2Vec2(0,26.4583)
b2Vec2(0,26.3167)
b2Vec2(0,26.1722)
b2Vec2(0,26.025)
b2Vec2(0,25.875)
b2Vec2(0,25.7222)
b2Vec2(0,25.5667)
b2Vec2(0,25.4083)
b2Vec2(0,25.2472)
b2Vec2(0,25.0833)
b2Vec2(0,24.9167)
b2Vec2(0,24.7472)
b2Vec2(0,24.575)
b2Vec2(0,24.4)
b2Vec2(0,24.2222)
b2Vec2(0,24.0417)
b2Vec2(0,23.8583)
b2Vec2(0,23.6722)
b2Vec2(0,23.4833)
b2Vec2(0,23.2917)
b2Vec2(0,23.0972)
b2Vec2(0,22.9)
b2Vec2(0,22.7)
b2Vec2(0,22.4972)
b2Vec2(0,22.2917)
b2Vec2(0,22.0833)
b2Vec2(0,21.8722)
b2Vec2(0,21.6583)
b2Vec2(0,21.4417)
b2Vec2(0,21.2222)
b2Vec2(0,21)
b2Vec2(0,20.775)
b2Vec2(0,20.5472)
b2Vec2(0,20.3167)
b2Vec2(0,20.0833)
b2Vec2(0,19.8472)
b2Vec2(0,19.6083)
b2Vec2(0,19.3667)
b2Vec2(0,19.1222)
b2Vec2(0,18.875)
b2Vec2(0,18.625)
b2Vec2(0,18.3722)
b2Vec2(0,18.1167)
b2Vec2(0,17.8583)
b2Vec2(0,17.5972)
b2Vec2(0,17.3333)
b2Vec2(0,17.0667)
b2Vec2(0,16.7972)
b2Vec2(0,16.525)
b2Vec2(0,16.25)
b2Vec2(0,15.9722)
b2Vec2(0,15.6917)
b2Vec2(0,15.4083)
b2Vec2(0,15.1222)
b2Vec2(0,14.8333)
b2Vec2(0,14.5417)
b2Vec2(0,14.2472)
b2Vec2(0,13.95)
b2Vec2(0,13.65)
b2Vec2(0,13.3472)
b2Vec2(0,13.0417)
b2Vec2(0,12.7333)
b2Vec2(0,12.4222)
b2Vec2(0,12.1083)
b2Vec2(0,11.7917)
b2Vec2(0,11.4722)
b2Vec2(0,11.15)
b2Vec2(0,10.825)
b2Vec2(0,10.4972)
b2Vec2(0,10.1667)
b2Vec2(0,9.83333)
b2Vec2(0,9.49722)
b2Vec2(0,9.15833)
b2Vec2(0,8.81666)
b2Vec2(0,8.47222)
b2Vec2(0,8.125)
b2Vec2(0,7.775)
b2Vec2(0,7.42222)
b2Vec2(0,7.06667)
b2Vec2(0,6.70833)
b2Vec2(0,6.34722)
b2Vec2(0,5.98333)
b2Vec2(0,5.61667)
b2Vec2(0,5.24722)
b2Vec2(0,4.875)
b2Vec2(0,4.5)
b2Vec2(0,4.12222)
b2Vec2(0,3.74167)
b2Vec2(0,3.35833)
b2Vec2(0,2.97222)
b2Vec2(0,2.58333)
b2Vec2(0,2.19167)
b2Vec2(0,1.79722)
b2Vec2(0,1.4)
b2Vec2(0,1)
b2Vec2(0,0.597224)
b2Vec2(0,0.191669)
b2Vec2(0,-0.216664)
b2Vec2(0,-0.627775)
b2Vec2(0,-1.04166)
b2Vec2(0,-1.45833)
b2Vec2(0,-1.87777)
b2Vec2(0,-2.3)
b2Vec2(0,-2.72499)
b2Vec2(0,-3.15277)
b2Vec2(0,-3.58333)
b2Vec2(0,-4.01666)
b2Vec2(0,-4.45277)
b2Vec2(0,-4.89166)
b2Vec2(0,-5.33332)
b2Vec2(0,-5.77777)
b2Vec2(0,-6.22499)
b2Vec2(0,-6.67499)
b2Vec2(0,-7.12777)
b2Vec2(0,-7.58332)
b2Vec2(0,-8.04166)
b2Vec2(0,-8.50277)
b2Vec2(0,-8.96665)
b2Vec2(0,-9.43332)
b2Vec2(0,-9.90276)
b2Vec2(0,-10.375)
b2Vec2(0,-10.85)
b2Vec2(0,-11.3278)
b2Vec2(0,-11.8083)
b2Vec2(0,-12.2916)
b2Vec2(0,-12.7778)
b2Vec2(0,-13.2666)
b2Vec2(0,-13.7583)
b2Vec2(0,-14.2528)
b2Vec2(0,-14.75)
b2Vec2(0,-15.25)
b2Vec2(0,-15.7528)
b2Vec2(0,-16.2583)
b2Vec2(0,-16.7666)
b2Vec2(0,-17.2778)
b2Vec2(0,-17.7916)
b2Vec2(0,-18.3083)
b2Vec2(0,-18.8278)
b2Vec2(0,-19.35)
b2Vec2(0,-19.875)
b2Vec2(0,-20.4028)
b2Vec2(0,-20.9333)
b2Vec2(0,-21.4666)
b2Vec2(0,-22.0027)
b2Vec2(0,-22.5416)
b2Vec2(0,-23.0833)
b2Vec2(0,-23.6277)
b2Vec2(0,-24.175)
b2Vec2(0,-24.725)
b2Vec2(0,-25.2777)
b2Vec2(0,-25.8333)
b2Vec2(0,-26.3916)
b2Vec2(0,-26.9527)
b2Vec2(0,-27.5166)
b2Vec2(0,-28.0833)
b2Vec2(0,-28.6527)
b2Vec2(0,-29.225)
b2Vec2(0,-29.8)
b2Vec2(0,-30.3777)
b2Vec2(0,-30.9583)
b2Vec2(0,-31.5416)
b2Vec2(0,-32.1277)
b2Vec2(0,-32.7166)
b2Vec2(0,-33.3083)
b2Vec2(0,-33.9027)
b2Vec2(0,-34.5)
b2Vec2(0,-35.1)
b2Vec2(0,-35.7027)
b2Vec2(0,-36.3083)
b2Vec2(0,-36.9166)
b2Vec2(0,-37.5277)
b2Vec2(0,-38.1416)
b2Vec2(0,-38.7583)
b2Vec2(0,-39.3777)
b2Vec2(0,-40)
b2Vec2(0,-40.625)
b2Vec2(0,-41.2527)
b2Vec2(0,-41.8833)
b2Vec2(0,-42.5166)
b2Vec2(0,-43.1527)
b2Vec2(0,-43.7916)
b2Vec2(0,-44.4333)
b2Vec2(0,-45.0777)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)
b2Vec2(0,-45.725)


I've noticed that it always stops at around (0, 0 - |shape's half_width|). For example, if you call bs.SetAsBox(60, 60), then the body will stop falling at (0, -60).

Is there something I'm missing here? This is really starting to get on my nerves, and I'm probably going to abandon the project completely if I can't get this solved.
Wow, I fell like an idiot now.

Instead of setting the world's lowerBound and upperBound, I set the lowerBounds and upperBounds. Completely fixed it.

Original thread: https://box2d.org/forum/viewtopic.php?t=3025