Reputation: 57
I am using matter. js to create a 2d scene. I apply a force on a body in the scene, this body hits other bodies but eventually all bodies stop moving due to friction and loss of energy.
Somehow I need to detect when all bodies in the scene have stopped moving. I am finding difficulty doing so since after going through the documentation I did not find a built in method to do the check for me. Also I tried iterating through the bodies in the scene and checking some attributes I thought would determine if the object was moving or still, this got me nowhere.
Does anyone know of a clean way to check if all bodies in the scene are not moving anymore?
Upvotes: 3
Views: 2561
Reputation: 26040
Did you try to loop through the bodies and check the property
http://brm.io/matter-js/docs/classes/Body.html#property_speed
and
http://brm.io/matter-js/docs/classes/Body.html#property_angularSpeed
if they are close to zero? (Remember that comparing any float to exactly zero will almost never give the behavior that you expect.)
Upvotes: 4