5
\$\begingroup\$

I have a loop, which updates all the physics, inside the loop I'm updating the position of the objects, first thing is the gravity, which pulls all the objects to the bottom. Now my question is, how do I manage the sleep/awake state of the object, let's say the object reached some static body, like ground. So it won't continue falling down because of the gravitation pull?

\$\endgroup\$
7
  • \$\begingroup\$ You could use a boolean flag on your objects, and just skip over them if they're supposed to be sleeping \$\endgroup\$
    – ThorinII
    Commented Oct 21, 2013 at 9:16
  • \$\begingroup\$ I was thinking about it, though if an object is sleeping, it will react differently to other objects. Let's say the object is on some surface sleeping, and another box is falling on it. the sleeping object should awake and react to the collision and remain above the surface. A more precise question is, how to maintain the object above surface and prohibit penetration of the surface? \$\endgroup\$ Commented Oct 21, 2013 at 9:23
  • \$\begingroup\$ I suppose then, you'll need a collision response system \$\endgroup\$
    – ThorinII
    Commented Oct 21, 2013 at 9:27
  • \$\begingroup\$ The ground will have to exert a force/impulse on the objects to stop them from penetrating it - and that should naturally extend to object-object collisions \$\endgroup\$
    – ThorinII
    Commented Oct 21, 2013 at 9:28
  • 2
    \$\begingroup\$ You've asked the wrong question. First you must learn about collision resolution, and then you can learn about sleeping. \$\endgroup\$
    – RandyGaul
    Commented Oct 21, 2013 at 9:28

1 Answer 1

1
\$\begingroup\$

You need collision resolution to handle object-ground collisions.

A basic example: check if the object is below/colliding with the floor, move it into a position where it does not collide, and set its velocity to make it either sit there, or bounce off (depending on how fast the object is moving downwards).

If you need more accurate physics Google will help you.

Sleeping is an optimisation for the engine such that it does not have to simulate the objects that are not doing anything interesting.

\$\endgroup\$
3
  • \$\begingroup\$ Thanks mate for your answer, I am going to check the proposed approach \$\endgroup\$ Commented Oct 21, 2013 at 9:40
  • \$\begingroup\$ That's fine - do you have the link to Randy's tut? \$\endgroup\$
    – ThorinII
    Commented Oct 21, 2013 at 9:41
  • 1
    \$\begingroup\$ @ThorinII gamedev.tutsplus.com/tutorials/implementation/… \$\endgroup\$
    – RandyGaul
    Commented Oct 21, 2013 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .