I've made a few classes to create soft body objects in libGDX using Box2D (specifically a circle and rectangle similar to these links).

The objects are constructed of a number of circle shaped Box2D bodies (hereafter deform points) connected together by distance joints which allow the object to "deform" when the deform points move around. Collision works more or less fine when the objects are colliding with other standard Box2D rigid bodies such as a box polygon (what they're sitting on):

Soft bodies colliding with polygon. Static bodies above.

The problem starts when two soft bodies collide. As you can probably guess from the way they're constructed, the two often pass through each other since the deform points for which Box2D handles collision are small and spaced apart, so they easily don't collide when the two soft bodies should. If the two bodies are placed like seen on the left in the following image, the circle passes through the square, rather than bouncing off the top of it as it should:

Soft bodies colliding with each other.

I've tried solving the problem (methods shown below) by tessellating the bodies more so that the deform points are closer together (left), which seems far too resource intensive and didn't affect much anyway. Then I tried enlarging the size of the deform points to fill the gaps (middle), which worked perfectly for the collision but as you can see caused problems mapping the texture to the object since the textures don't appear to collide. After that I tried to bound the outside of the object using polygon bodies connected between deform points using revolute joints, this works with the texture better and does prevent objects from falling through each other, but it stops the object from deforming properly.

Left: more tessellation. Middle:

I can't think of any more ways to tackle this problem, but I'm very new to Box2D and libGDX and maybe I'm overlooking a much more simple solution. I'll give any ideas a shot.


1 Answer 1


If the middle one works physically and the only problem is the mapping of the texture onto the deform points (and since the deform points don't account for the outer edge of the soft body), wouldn't it be possible to map the texture to points that are offset from the deform point by some value?

Try locking rotation of the deform points, you can do that by setting fixedRotation to true on the BodyDefinition, then for each deform point associate it with a Vector2 that is the offset from the center of the deform point to the point where the texture will be mapped. Unless you're already using it you could potentially use the setUserData to store the offset vector on the deform point.

  • \$\begingroup\$ I don't know why I didn't think of that myself but it worked perfectly, thanks very much! Fixing the rotation also stopped the bodies from sliding along the ground after bouncing which was confusing me as I thought it was to do with the friction values, but as it turns out it was the circles acting as wheels. Marked as answer :) \$\endgroup\$ Commented Sep 25, 2015 at 0:09

You must log in to answer this question.

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