[Resolved] object.isMoving ???

Is there a way I can determine if an object, in this case a ball, is still rolling and performWithDelay until it’s stopped or times out.

So something like:
if not object.isMoving then
make ball disappear
elseif ball has been rolling for 10 seconds then
make ball disappear
end

It’s the ‘object.isMoving’ bit that I can’t figure out how to determine. Is there something as simple as an .isMoving attribute, or similar that I can use for this function? [import]uid: 157954 topic_id: 30517 reply_id: 330517[/import]

Hi Brad,

Yes, you can use [lua]ball:getLinearVelocity()[/lua] to determine if the ball is moving, like this:

[blockcode]
local isBallMoving = function()
– Get the velocity of the ball
local vx,vy = ball:getLinearVelocity()

– Define the minimum velocity for which we consider the ball to be no longer moving. Set to 0 if you want to test whether the ball is truly 100% still (not recommended, as there could always be some slight imperceptible movement)
local minVelocity = 5

if (vx*vx)+(vy*vy) <= minVelocity*minVelocity then
return false
else
return true
end
end
[/blockcode]

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 30517 reply_id: 122282[/import]

I was using a variable ismoving true/false with these functions in transitions:

onStart and onComplete
But if you are using physics, you can:

use a runtime listener asking for x’s and y’s
use angularVelocity, linearDamping, angularDamping of that object?
isAwake?

Could this help you? [import]uid: 116842 topic_id: 30517 reply_id: 122283[/import]

You guys are geniuses!

Thanks heaps [import]uid: 157954 topic_id: 30517 reply_id: 122368[/import]

We know, but thanks anyways. [import]uid: 116842 topic_id: 30517 reply_id: 122403[/import]

Hi Brad,

Yes, you can use [lua]ball:getLinearVelocity()[/lua] to determine if the ball is moving, like this:

[blockcode]
local isBallMoving = function()
– Get the velocity of the ball
local vx,vy = ball:getLinearVelocity()

– Define the minimum velocity for which we consider the ball to be no longer moving. Set to 0 if you want to test whether the ball is truly 100% still (not recommended, as there could always be some slight imperceptible movement)
local minVelocity = 5

if (vx*vx)+(vy*vy) <= minVelocity*minVelocity then
return false
else
return true
end
end
[/blockcode]

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 30517 reply_id: 122282[/import]

I was using a variable ismoving true/false with these functions in transitions:

onStart and onComplete
But if you are using physics, you can:

use a runtime listener asking for x’s and y’s
use angularVelocity, linearDamping, angularDamping of that object?
isAwake?

Could this help you? [import]uid: 116842 topic_id: 30517 reply_id: 122283[/import]

You guys are geniuses!

Thanks heaps [import]uid: 157954 topic_id: 30517 reply_id: 122368[/import]

We know, but thanks anyways. [import]uid: 116842 topic_id: 30517 reply_id: 122403[/import]