Articles

Help me replace my broken Mac Mini!

Click here to lend your support to: Help me replace my broken mac mini and make a donation at www.pledgie.com !

About this tutorial

Learn about Chipmunk Physics Engine and how to start developing games for the iPhone and other platforms.

Contents

  1. Introduction
  2. Setup
  3. Basic Concepts
  4. Initializing Chipmunk
  5. Defining the ball's body and shapes
  6. Tracking the ball's movements
  7. Defining the floor's body and shapes
  8. Evaluating the results & Conclusion
  9. Download the complete project

Evaluating the results

All this code and rules had an objective, physics simulation. You could probably had achieved the exact same results with half the code but now we'll find why using Chipmunk is the better option:

  • Try changing the friction of all the floor's shapes from 0.1 to 0.5. Run the code, the fall will now lose more velocity.
  • Try increasing or decreasing the gravity and/or the ball's mass to several different values.
  • Try editing the shapes a bit.

Finally, you may have noticed that all the shapes had their elasticity property set but it doesn't seem to have any effect on the simulation. To enable elastic body's simulation add the following code after setting up the gravity of the space (the order doesn't matter as long as it's after the space was created obviously):

// Add some elastic effects to the simulation

space->elasticIterations = 10;

Now if you run the simulation and/or play with the elasticity values of the shapes you'll see the ball bouncing off the floor when it falls.

Conclusion

Though flexible and easy to use Chipmunk requires some time and effort to understand how it works and some of its concepts. In this tutorial I hope to have been clear enough to the point where anyone could use Chipmunk's basic features: space, bodies and shapes.

There is a lot more to be said and learnt including forces, collision detection and joints. I hope to be back with a follow up covering some of those topics.



Donate

If you find this article useful and enjoy it, consider donating, even a small amount goes a long way to keep the articles up-to-date and to fund new ones.