How do I detect when all physics object has finally come to a complete stop ?

0 favourites
  • 5 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • How do I detect when all physics object has finally come to a complete stop ?

  • You can add all physics sprites into a family and use "Is sleeping" event to check if all sprites are not moving.

    However, I noticed that in Box2D engine physics object are often reluctant to sleep - they continue to move/shift a little for a long time.

    I recommend using Chipmunk behavior instead.

  • I would have a variable called all = 0

    Then you can have a for each loop ( for each physics object )

    Check Y and X velocity of each add them up ( use abs() so it is always a positive number ) and when below ( just a guess ) 10 it counts as not moving and if so add 1 to all variable. Just under the loop reset all variable back to 0

    Now if you have 20 physics object and they all register as not moving, that all variable will reach 20 before being reset, so just before resetting add another event/sub-event, if all = 20 do whatever you need to do when they all stopped moving.

    Depending on your game you may need to keep track of X and Y velocities separately, You can use a number higher than 10 or lower, you can decide after a few test runs. I just checked my golf game, I use < 10 for X velocity and < 0.2 for Y velocity and if both are met trigger not moving.

  • BadMario, your method is insane ! You must be a genius, this is way too much for me.

    I will use dop2000 is sleeping method for now.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's only a few events and it works. I use it in a bunch of games. If the sleep method works, cool, but like he said, they keep moving slightly even when it looks like they are done

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)