Physics property checks

Is there a way to do the following?

  1. Check if a display object is part of a physics system? I have some code where I am checking the velocity of objects, but obviously getLinearVelocity() will throw errors if the object body hasn’t been added to the physics yet.

  2. Check if a body is sleeping? I know about body.isSleepingAllowed(), but shouldn’t there also be something like body.isSleeping()? I’d like to remove objects if they come to rest. What is the best way to do that? [import]uid: 52127 topic_id: 9855 reply_id: 309855[/import]

For the first one you can do something like this:

  
if object["getLinearVelocity"] then  
 local linX, linY = object:getLinearVelocity()  
end  
  

And the isBodyActive property may be what you need for the second - http://developer.anscamobile.com/reference/index/bodyisbodyactive [import]uid: 5833 topic_id: 9855 reply_id: 35958[/import]

Thanks for the first suggestion, that works.

isBodyActive always returns true though, unless you set it to false yourself. If I throw a ball for example, I want to remove it if it comes to a stop (or close to a stop for all intents and purposes). I guess the only way to do that is to continuously check the x and y velocities of every ball on the screen and remove the ball if those values are both below a certain threshold. [import]uid: 52127 topic_id: 9855 reply_id: 35980[/import]

Ah right, well 1 out of 2 isn’t bad :slight_smile:

That might be the easiest way and wouldn’t be too bad depending on how many objects there are at any one time. [import]uid: 5833 topic_id: 9855 reply_id: 35982[/import]

Does the body.isAwake work?
http://developer.anscamobile.com/reference/index/bodyisawake

So:

if not object.isAwake then  
 object:removeSelf()  
end  

[import]uid: 49205 topic_id: 9855 reply_id: 36343[/import]

Why doesn’t Corona provide an event that fires when a body just slept and/or with a supplied velocity threshold that falls within range? [import]uid: 166680 topic_id: 9855 reply_id: 120769[/import]

Why doesn’t Corona provide an event that fires when a body just slept and/or with a supplied velocity threshold that falls within range? [import]uid: 166680 topic_id: 9855 reply_id: 120769[/import]