I spent the weekend implementing 2D “jelly” physics similar to The Floor is Jelly.

TL;DR: My working demo with JavaScript code is available here. It was written in three days, so it’s a bit rough around the edges, but it gets the basic idea across.

If you haven’t heard, The Floor is Jelly was released the other day, and generated some minor buzz in the indie gaming community. If you haven’t heard of it, it’s worth checking out. The game is gorgeous, and explores several cool gameplay mechanics as you progress through the world.

Not surprisingly, most of these mechanics have something to do with the floor (and walls, etc) being made of jelly. After playing through it for a while, I decided that I wanted to try to implement it.

The only post the author made on the technique is fairly high level but descriptive enough. The important things to note are as follows:

Additionally, while playing I noticed the following two facts

Knowing this, it was fairly straightforward to model these facts in code. It’s in JavaScript, mainly because I wanted to be able to share this as an online demo.

I’m not stellar at explaining things, so for more info you should just look at the code. It’s about 350 lines, but most of that is rendering or input handling. The physics calculations themselves are only about 100 lines.

You can see it here.

The biggest caveat here is that this implementation isn’t optimized much, and would need a some work to be used in a serious game. It still runs at around 60fps on my machine, but would degrade quickly for larger levels.