Simple 2D soft bodies in Box2D

Box2D is an excellent, widely used and completely free 2D physics engine. It has support for variety of 2D shapes and joints but there’s no out of the box support for soft bodies and so if you want one you have to do it yourself.

I’ve made an experiment and implemented simple round soft bodies using a couple of circles linked using distance joints, then thought why not to share it. Here’s how you use the code:

b2ExSoftCircleBodyDef def;
def.numParts = 10; // Number of linked internal circles
def.radius = 10.0f;
def.center = b2Vec2(0.0f, 15.0f);
def.softness = 0.5f; // Softness within 0..1 range
b2ExSoftCircleBody* body = b2ExSoftCircleBody_Create(world, &def);

And this is the result:

This slideshow requires JavaScript.

Get the demo and source code from GitHub and use it freely 🙂

Advertisements

About Maciej

Game developer with passion
This entry was posted in physics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s