corona Build: 2012.894 physics problems

Is anyone else having problems with physics on the latest build of corona 2012.894. I have a game that has objects on screen the gravity is initially set up to 0 with physics.setGravity(0,0). I then have arrow buttons on screen, up button, down button etc. I have functions set up for each button that change the gravity in the game according to the button pressed e.g. gravityUp function event sets gravity with physics.setGravity(0, -9.81). This worked fine for the 2012.840 build but unfortunately I just updated to the latest build and this code isn’t working anymore. I have placed print statements inside the functions so i know it is getting into the function and setting the gravity.

I also turned on the physics.setDrawMode(“hybrid”) and i notice that the objects are grey instead of yellow

Thanks [import]uid: 163580 topic_id: 31012 reply_id: 331012[/import]

Hi there,

If the objects are in grey, that means they are “sleeping”. Box2D puts objects to sleep (to save processing time) if they haven’t moved or collided with anything for a few seconds. Sleeping objects are not simulated in the Box2D physics engine, and thus won’t respond to gravity until they are woken up. Since your starting point is zero gravity, the objects get put to sleep very quickly. Box2D will wake a sleeping object automatically if something collides with it, but not simply because gravity has changed from zero to non-zero.

What this means is, when you change the gravity, you should proactively wake up all of your objects by looping through them and setting their [lua]isAwake[/lua] property. See more info here: http://developer.coronalabs.com/reference/index/bodyisawake.

Hope this helps.

  • Andrew

[import]uid: 109711 topic_id: 31012 reply_id: 124009[/import]

By default, Box2D bodies not involved in a collision will “sleep” after a couple of seconds. This reduces overhead, but in some cases you may not want this behavior.

You can override this behavior on a given body with body.isSleepingAllowed = false, but you can also override this globally for all bodies in the world by using an optional boolean parameter in start:

physics.start( true ) – prevent all bodies from sleeping
physics.start( false ) – default behavior; bodies may sleep [import]uid: 13632 topic_id: 31012 reply_id: 124029[/import]

Hi there,

If the objects are in grey, that means they are “sleeping”. Box2D puts objects to sleep (to save processing time) if they haven’t moved or collided with anything for a few seconds. Sleeping objects are not simulated in the Box2D physics engine, and thus won’t respond to gravity until they are woken up. Since your starting point is zero gravity, the objects get put to sleep very quickly. Box2D will wake a sleeping object automatically if something collides with it, but not simply because gravity has changed from zero to non-zero.

What this means is, when you change the gravity, you should proactively wake up all of your objects by looping through them and setting their [lua]isAwake[/lua] property. See more info here: http://developer.coronalabs.com/reference/index/bodyisawake.

Hope this helps.

  • Andrew

[import]uid: 109711 topic_id: 31012 reply_id: 124009[/import]

By default, Box2D bodies not involved in a collision will “sleep” after a couple of seconds. This reduces overhead, but in some cases you may not want this behavior.

You can override this behavior on a given body with body.isSleepingAllowed = false, but you can also override this globally for all bodies in the world by using an optional boolean parameter in start:

physics.start( true ) – prevent all bodies from sleeping
physics.start( false ) – default behavior; bodies may sleep [import]uid: 13632 topic_id: 31012 reply_id: 124029[/import]