Search code examples
iphonecocoa-touchchipmunk

How to detect stack objects falling down


In my game, Objects are falling down and I have to catch that object and have to create a stack. I am doing this by using chipmunk physics engine. I am able to create stack but I don't understand how to detect that stack is falling like "Tower Bloxx" game.

If any one knows it please help me out.


Solution

  • You need to calculate the forces and torques on each object.

    Gravity acts on the center of mass of an object. If this object overhangs another object, then there could be a torque that could roll the object off.

    If you've got the physics down so that it's realistic, then you can detect whether the stack is stable or not by monitoring the direction of the velocity for each object. If it's changing sign, and the magnitude is getting smaller, then it's stabilizing. (If it's zero, it is stable already.)