Dynamic Object Gets Static Itself

I have physics body in my project, with a rectangle form. However, when I set gravity and a rectangle falls down on a static object (wall) and when bouncing is finished, my dynamic rectangle instantly gets static and I can’t move it anymore (I’m using accelerometer to move it). I haven’t found any solutions till now. Does anyone know what’s going on? Because in one of the sample projects (It’s name is “ShapeTumbler”) objects behave exactly like I explained. I want my dynamic object to stay dynamic.

Are you sure it’s static?  Are you in hybrid or debug mode to see what the bodies are actually doing?

physics.setDrawMode( “hybrid” )

https://docs.coronalabs.com/api/library/physics/setDrawMode.html

This will overlay colored blocks on your objects that identify what state they are in.

Rob

Hi @5w0rdm4st3r,

Without seeing your project, my guess is that the dynamic body is “falling asleep” as bodies do, by default, if there is no physical interaction on them after a couple seconds. That will make it seem “static” but bodies will simply never change body type on their own. Once a body is sleeping, it will not move under influence of the accelerometer, because that is not a “physical” force, and the physics engine doesn’t regard that as being a physical force to wake the body.

The typical solution is to disallow bodies to fall asleep:

https://docs.coronalabs.com/api/type/Body/isSleepingAllowed.html

Best regards,

Brent

Thanks for your replies  :) 

@Rob Miracle,
Yes, I’ve been looking to the body with “hybrid” mode, and everything happened like I explained. Object was dynamic and it was getting static as it stopped moving. 

and @Brent Sorrentino,
Thanks, myRect.isSleepingAllowed = false worked for simulator and It’s most likely to work on a device when I’ll test it. 

 

Hi @5w0rdm4st3r,

Good to hear! Just to clarify the point I made earlier, the body type can never change automatically from “dynamic” to “static” (or from any type to another type). The only way that can happen is if you command it to happen via the “.bodyType” property. What is happening is that the dynamic body is falling asleep… so it remains a dynamic body, just a sleeping one. :slight_smile:

Brent

Are you sure it’s static?  Are you in hybrid or debug mode to see what the bodies are actually doing?

physics.setDrawMode( “hybrid” )

https://docs.coronalabs.com/api/library/physics/setDrawMode.html

This will overlay colored blocks on your objects that identify what state they are in.

Rob

Hi @5w0rdm4st3r,

Without seeing your project, my guess is that the dynamic body is “falling asleep” as bodies do, by default, if there is no physical interaction on them after a couple seconds. That will make it seem “static” but bodies will simply never change body type on their own. Once a body is sleeping, it will not move under influence of the accelerometer, because that is not a “physical” force, and the physics engine doesn’t regard that as being a physical force to wake the body.

The typical solution is to disallow bodies to fall asleep:

https://docs.coronalabs.com/api/type/Body/isSleepingAllowed.html

Best regards,

Brent

Thanks for your replies  :) 

@Rob Miracle,
Yes, I’ve been looking to the body with “hybrid” mode, and everything happened like I explained. Object was dynamic and it was getting static as it stopped moving. 

and @Brent Sorrentino,
Thanks, myRect.isSleepingAllowed = false worked for simulator and It’s most likely to work on a device when I’ll test it. 

 

Hi @5w0rdm4st3r,

Good to hear! Just to clarify the point I made earlier, the body type can never change automatically from “dynamic” to “static” (or from any type to another type). The only way that can happen is if you command it to happen via the “.bodyType” property. What is happening is that the dynamic body is falling asleep… so it remains a dynamic body, just a sleeping one. :slight_smile:

Brent