Detect if physics object is no longer in motion?(at rest even)

Hi,

So far everything has gone somewhat smoothly with my app development.  I was just wondering if it was possible to detect if a physics object is no longer in motion, at rest, or whatever you would call it.  I would like to use this as a means to “end” that try at the level, as the ‘player’ bouncing off the bottom will come into play and I can’t use simple collision to end the level.

I suppose I could use bucket-like things for the ‘player’ to fall into and when it collides with the bottom of one it will pause physics, tally the score and whatnot.  Was just curious if it was possible, I can’t seem to find it via search.

Thanks in advance!

Hi @nicefrog,

The best approach is to loop through all of the physics objects in a Runtime loop, checking their linear velocity within a certain allowed range.

[lua]

local lx, ly = object:getLinearVelocity()

[/lua]

Remember that a physics body will rarely have 0,0 values after it has been set in motion. Even if it appears to stop, it may be moving on low-decimal values, so you need to check within a certain + and - range (both x and y) for whatever “feels right” in your game. Some people also calculate the triangular math using these values (for example, the motion on the 45 degree vector), but in my testing, if you want to just check “is the object stopped to a reasonable degree” like Angry Birds, just checking direct horizontal and vertical motions is enough.

Hope this helps,

Brent Sorrentino

Thank you very much, Brent!

Hi @nicefrog,

The best approach is to loop through all of the physics objects in a Runtime loop, checking their linear velocity within a certain allowed range.

[lua]

local lx, ly = object:getLinearVelocity()

[/lua]

Remember that a physics body will rarely have 0,0 values after it has been set in motion. Even if it appears to stop, it may be moving on low-decimal values, so you need to check within a certain + and - range (both x and y) for whatever “feels right” in your game. Some people also calculate the triangular math using these values (for example, the motion on the 45 degree vector), but in my testing, if you want to just check “is the object stopped to a reasonable degree” like Angry Birds, just checking direct horizontal and vertical motions is enough.

Hope this helps,

Brent Sorrentino

Thank you very much, Brent!