< Irrelevant.dev

Hairball Experiment

Published On: December 17, 2021 🌭?
Game Unity

Hairball Simulation

I've always loved dynamic rope effects in games. I've often wondered how you'd go about building something like that. A while back I decided to find out, and take a shot at implementing something. It was time to just get in there1.

Originally I was going to fall back on Chain or HingeJoint in the Unity Physics System. After a little searching, I came across a non-physics-engine based rope simulation technique using Vertlet Integration2 from this video.

Adding some configuration, and tweaks on top of this technique, I ended up building a weird hairball simulation. There are a bunch of "rope" objects, with "gravity" pulling them away from the mouse position, but anchored to the mouse position. The result is below. It's surprisingly satisfying to play around with, and see how the ropes react and settle. Feel free to take a look at the code.

A bug with Unity's new input system makes the position appear offset if the canvas is not taking up most of the window. If your window is very large, you may have to move the cursor relative to the top left of the browser window to see the simulation.

  1. "Just Gotta Get In There" a concept from Butterscotch Shenanigans, https://podcastaddict.com/episode/127973453
  2. Vertlet Integration, https://en.wikipedia.org/wiki/Verlet_integration