0
votes

I have a jumping game. There are some items that when the jumper collects then it stays in the air for 3 seconds and then falls down. For that I have done the following:

// to stop the body in the air
body->SetGravityScale(0);
body->SetLinearDamping(7); // don't want abrupt stopping

To make body to fall again from the air back to the ground after 3 seconds I do:

body->SetGravityScale(1);                
body->SetLinearDamping(0);

But it continues to stay in the air. Only when I apply a small impulse towards down it starts to fall. Why?

EDIT: I have explicitly set:

m_world.SetAllowSleeping(false);

but anyways, I should apply linear impulse to make him fall back or simply do:

body->SetAwake(true);

It turns that body is sleeping even if m_world.SetAllowSleeping(false);. Is this OK?

1
First thing I would do is look at the debug draw display, then you can tell us whether the body is actually sleeping or not.iforce2d
When I commented the line containing m_world.SetAllowSleeping(false); on debug draw it really slept when I set body->SetGravityScale(0);. I have explicitly set m_world.SetAllowSleeping(false); and it worked without body->SetAwake(true);. Seems something when wrong with compilation and it did not update the executable.Narek

1 Answers

0
votes

Check your world and see if it have gravity, even with gravityScale = 1 your body won't fall without gravity in the world.

If your problem is not there, check if your body can be affected by gravity checking if the body is a dynamic body.

I think it would be best if I commented it in your question, but I don't have enough Rep for that :/

Hope it helps :)