0
votes

I am developing a sidescroller on iOS where, if the character jumps I apply an impulse to a box2d body and let interia do the rest ( it's a low gravity game so sometimes the character is in the the air for a while). My problem is if any type of notification is recieved i.e. text meassage or mail alert on the ios device the body will just stop and drop like a rock if it is in the air. It loses all momentum/ inertia and it's like it was never moving. Can anyone please help me out. Any thoughts or suggestions are greatly appreciated.

1
I suspect a bug in your project. See if you pause or stop or otherwise reset the physics simulation at that point. Or if you use delta time for Box2D's timestep, use a fixed timestep instead.LearnCocos2D

1 Answers

0
votes

I've had a similar problem to this. I assume you're pausing/resuming with the CCDirector. Check the dt of your update method when you resume after the pause. For me, I was pausing, then coming back and the dt was huge, like 30 seconds, so it was feeding that value to the physics engine and of course the object had rolled to a stop by then.

The way I solved was hack-ish, I just set an if statement to return if the dt was greater than a second. Then the next time update was called, it was a sane value, like 1/30th of a second and everything was back to normal.