webdevpuneet.com

Matter.js Soft-Body Jelly Blobs — Free Squishy Physics Snippet

Matter.js Soft-Body Jelly Blobs · Animations · Plain HTML, CSS & JS · Live preview

CategoryAnimations

Copy & paste

Source Code

Requires
<div class="jl">
  <div class="jl-bar">
    <h2>Jelly</h2>
    <label>Firmness <input type="range" id="jlStiff" min="0.01" max="0.3" step="0.01" value="0.06"><output id="jlStiffOut"></output></label>
    <label class="jl-check"><input type="checkbox" id="jlSkeleton"> Show skeleton</label>
    <button type="button" id="jlDrop">Drop jelly</button>
    <button type="button" id="jlReset" class="ghost">Reset</button>
  </div>
  <div class="jl-stage" id="jlStage"></div>
  <p class="jl-hint">Grab a jelly and fling it. Lower firmness = wobblier jelly.</p>
</div>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Ring-and-spoke soft bodies
A centre particle plus 18 edge particles.
Rim springs
The skin between neighbours.
Bending springs
Skip-one links prevent kinks.
Volume spokes
Softer springs from the centre.
No self-collision
Unique negative group per jelly.
Smooth glossy skin
Quadratic curves plus a highlight.
Live firmness control
Updates every spring in place.
Skeleton view
Each spring type shaded differently.

About this UI Snippet

Soft Bodies in Matter.js — Particles, Three Kinds of Spring and a Smooth Skin

Screenshot of the Matter.js Soft-Body Jelly Blobs snippet rendered live

Matter.js simulates rigid bodies: a box never bends. Soft bodies are faked by joining many small rigid particles with springs — the same trick used in countless games — and hiding the machinery behind a smooth outline. This snippet builds wobbly jelly blobs that way. Tick "Show skeleton" to see what's really moving.

A ring and a centre

Each jelly is a centre particle plus a ring of 18 edge particles. Particles use inertia: Infinity so they don't spin, and they're invisible; only the outline is drawn.

Three kinds of spring, three jobs

- Rim springs join each ring particle to its neighbour. They are the skin and keep the circumference. - Skip-one springs join each ring particle to the one after next. Without them the skin can fold into sharp kinks; they give it bending resistance. - Spokes join the centre to every ring particle. They hold the volume, so a jelly squashes and bounces back instead of collapsing flat. Spokes are a little softer than the rim, which makes the blob squish before it stretches.

stiffness sets how firmly each spring returns to its rest length, and damping stops endless wobbling. Matter also ships Composites.softBody (a grid of particles); a ring gives a rounder, more jelly-like shape.

Collision groups stop self-collision

Particles of one jelly sit close together; if they collided with each other, the jelly would jitter and burst. Body.nextGroup(true) returns a fresh negative group per jelly, and bodies sharing a negative group never collide — while different jellies, with different groups, still bump into each other.

Drawing the skin

In afterRender, a closed path runs through the midpoints between ring neighbours, using each particle as a quadratic control point. That turns an 18-sided polygon into a smooth blob, and a glossy highlight follows the centre particle.

Live firmness

The slider changes the stiffness of every existing spring in place — turn a firm jelly floppy mid-bounce.

Step by step

How to Use

  1. 1
    Watch them landThree jellies drop and squish over the obstacles.
  2. 2
    Fling oneGrab a jelly anywhere and throw it.
  3. 3
    Change firmnessLower it for wobbly jelly, raise it for firm.
  4. 4
    Show the skeletonSee the rim, bending and spoke springs.
  5. 5
    Drop moreEach new jelly gets a random size and colour.

Real-world uses

Common Use Cases

Squishy landing page decorations
Add draggable jelly blobs to a hero section as a playful detail. The firmness slider lets you tune from wobbly to almost rigid before you commit to a feel.
Slime characters and soft objects
Prototype game characters or items that squash and bounce. Rim, bending and spoke springs give a stable blob that does not collapse or kink.
Learning how soft bodies are faked
Tick Show skeleton to see the particles and springs behind the glossy outline, and learn why Matter.js builds soft bodies from many small rigid parts.
Fidget and stress-relief widgets
Offer a calming toy on a break page or app idle screen: drag, fling and watch the jellies bounce off each other and the walls.
Creative coding experiments
Create organic motion from simple rules, then tweak the stiffness values or the number of edge particles around the centre to design your own wobble.
Related: Matter.js Rope Bridge
Related: Morphing Liquid Blob
A CSS/SVG blob without physics: Morphing Liquid Blob.

Got questions?

Frequently Asked Questions

Build it from small particles joined by Constraints with moderate stiffness and some damping. A ring of edge particles with neighbour springs, skip-one springs and spokes to a centre particle gives a round, squishy body. Give all its particles one negative collision group so they don't collide with each other.

They connect each edge particle to the one two places along, which resists sharp bending. Without them the outline can fold into kinks when squashed.

Usually its particles are colliding with each other. Use Body.nextGroup(true) to create a negative group for each soft body. Very high stiffness with few constraint iterations can also make it unstable.

Collect the edge particles in order and draw a closed path through the midpoints between neighbours, using each particle as a quadratic curve control point.

Yes. Constraints are plain objects; set constraint.stiffness and the next simulation step uses the new value.