Physics: How to determine if object has stopped moving

Hi.

I have an object acting under a physics enviornment and I would like to call a function once the object has come to a stop. Any ideas? [import]uid: 64736 topic_id: 12756 reply_id: 312756[/import]

Take a look at body.isAwake

http://developer.anscamobile.com/reference/index/bodyisawake [import]uid: 10478 topic_id: 12756 reply_id: 46786[/import]

In which event would I check that state? [import]uid: 64736 topic_id: 12756 reply_id: 46787[/import]

best would be checking it in your main game loop, enterframe for example… but any of the looping events should do it accelerometer, etc… [import]uid: 10478 topic_id: 12756 reply_id: 46788[/import]

OK. Thanks.

So there isn’t a listener within the object itself? I saw this in the documentation for the postCollision event and it made me curious as to what it was hinting at:

“Note: The “postCollision” events are quite noisy, and may report many times per contact and may affect performance. Therefore, you should only listen for these events if you need post-collision events, and we also recommend that you use local listeners within the objects of interest, rather than listening globally to all “postCollision” events in the world.” [import]uid: 64736 topic_id: 12756 reply_id: 46789[/import]

Depending on the implementation and use case, you might notice there will be a delay until the object comes to a complete stop.

It is common practice to check the object’s velocity like this:

local threshold = 0.3 local vx,vy = yourobject:getLinearVelocity() local m = math.sqrt((vx\*vx)+(vy\*vy)) if m<threshold then>do your thing<br>end

Hope this helps.

Alex. [import]uid: 4572 topic_id: 12756 reply_id: 46806[/import]