Greetings. I’m wondering if it would be possible to check with a python if a scene object is in “sleep”,
I am talking about checking physics status?
Edit: I semi-solved my current problem with the following check:
#Sum works since getVelocity() returns a list
if sum(object.getVelocity()) == 0.0:
Of course this wasn’t a literal answer to my question.
A better way to check the linear velocity of it was zero would be to use:
if object.getVelocity().length == 0:
I’m afraid I don’t know a proper way. But you can make sure that it isn’t going to sleep by checking the ‘no sleep’ option in the physics panel, and you can force it either way by using enable and disable dynamics.
Thanks for the length-method. I was just looking options to run a script only if an object was not moving
I would use care when comparing floating point values with “==”. Floating point math is no exact and there are numbers that cannot be directly represented. With floats it is usually a good idea to see if your value is “really close” to your target value instead of directly equal.
if math.fabs(object.getVelocity().length) < 0.001: