4A Soft Body Physics Toy

Let’s take a look at some code for Gauss-Seidel relaxation on a chain of springs joined together to make a soft body. We’ll start with our Pool End Game code from Chapter 3 with all of the pool game-specific code removed. Technically what I’m about to show you is a toy, not a game, because while you can play with it, there is no concept of winning or losing or even a score. Let’s call it the Ball and Spring Toy.

The Ball and Spring Toy lets you play with a body made up of a bunch of balls connected by constraints. The constraints can be either stick-like (with no springiness) or spring-like (with lots of springiness). You can cycle through various types of bodies and you can apply impulses to them to see how they react. ...

Get Introduction to Game Physics with Box2D now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.