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?
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
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?
Take a look at body.isAwake
http://developer.anscamobile.com/reference/index/bodyisawake
In which event would I check that state?
best would be checking it in your main game loop, enterframe for example... but any of the looping events should do it accelerometer, etc...
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."
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:
1 2 3 4 5 6 | local threshold = 0.3 local vx,vy = yourobject:getLinearVelocity() local m = math.sqrt((vx*vx)+(vy*vy)) if m<threshold then do your thing end |