Dungeon Slime

Hey everyone, I’ve gotten a couple asks for some breakdowns of the techniques im using to render and simulate the slime for my game, Dungeon Slime. You can check out a short video here for context.

As always, I don’t claim to be an authority on any of the topics I’m about to cover, so if you can see a better way to do anything please feel free to call it out! I’d be happy to improve anything :slight_smile:

To summarize briefly what’s going on here, there is a procedural mesh generating the skin of the slime. The vert positions are based on metaballs. The ball positions and behaviors are based on 64 simulated rigid body spheres that are constrained and driven by my gameplay code.

The procedural mesh component is driven by a plugin https://github.com/andyrst/ue4_metaballs (Thank you Andy Harchenko!). I made a couple tweaks to the plugin to expose some behaviors to blueprint, such as setting individual ball mass, and getting an individual ball’s location.

One of the other tweaks i made was to generate a second procedural mesh with the exact same set of data, except reversed so that it renders inside-out. The reason for this is to render it to the custom depth buffer. With that we can generate some nice depth-based effects like subsurface scattering or depth-based opacity. One other added benefit is to use it for internal triangle culling.

An important note here is that the procedural mesh component should never try and add a vertex outside of the bounds of the actor that the plugin defines, otherwise it can lead to some pretty nasty crashes. I created a sanitizing check before setting a ball’s updated position, just to sidestep the crash. At some point I’ll try and look more in-depth as to why it’s crashing and try and solve it for real, but for now, just checking if a ball’s location is safe first seems to work fine.

The movement behavior of the slime is based on the simulation, where 64 spheres are controlled by user input. The force I apply when you hit “forward” falls off based on the squared distance from the ball to the average location of all the balls. What this achieves is that the slime gets an undulating, inconsistent movement as you shlorp around.

Each ball is attracted to the average ball location, getting more powerfully pulled back to the center the farther it moves away. This achieves a level of elasticity and maintains the form of the slime.

Now that we have both a set of simulating balls, and a procedural mesh running that renders metaballs, the only thing left to do is to update the metaballs plugin with the sphere location before rendering. You can achieve this through blueprint by using the built in Set Ball Transform function on the actor provided by the plugin.

I hope this has given people a good place to start on their own, goopy slime projects. If you’re interested in seeing more and following my game as it develops, follow me on twitter!

Feel free to reach out directly with any questions or comments you have, thanks everyone!

1 Like