b2Body::SetLinearVelocity() does not works

hello, everyone.
In my programme, when the gravity of b2World is (0, 0), b2Body::SetLinearVelocity() does not works.
The object I invoke SetLinearVelocity() on is always unmovable.And the mass of the object is non-zero.It is a dynamic body.
Why? Help me please.Thanks.

This is log printed from game main loop:

velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=0.000000
position=(5.000000, 7.500000)
velocity=10.000000 ---------------------------------->invoke SetLinearVelocity()
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
velocity=10.000000
position=(5.000000, 7.500000)
I'm using SetLinearVelocity with no gravity too, and it is working (at least in my version of Box2D).
Are you sure you are calling the world's step function between your logs ? You also have to wake up the body in order for it to move (SetLinearVelocity is not enough).

Also, velocity should be a vector, and you are displaying a scalar.
You should show some more code.
Gnurfos wrote:
You also have to wake up the body in order for it to move (SetLinearVelocity is not enough).


Thanks Gnurfos.

My code: 😳
bool doSleep = true;
world = new b2World(gravity, doSleep);

I set doSleep with "true". I'm sorry I ignore it.
Gnurfos, Thanks very much. 🙂
You can still keep doSleep=true (and probably should, if you wish good performance).
You just have to wake up the impacted body when you do SetLinearVelocity on it.

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