So, lets get to the point here: Blowing stuff up is cool.
That statement probably will put me on a list somewhere — I mean virtually blowing stuff up is cool. In games, you hit something, and pieces of it fly apart, fragments go everywhere, cool particle effects, awesome sounds, all that feedback feels very satisfying. But sometimes, in a lot of games, that feedback is just par for the game. Like, a quick flash, some little sound byte, you reticle lights up, and it’s like, “OK, I did the thing.” but it’s not very gripping. To get that level of immersion, players need to not just see something break, but really feel it. Particles can only do so much – people want to see the result of their actions. They want to see stuff break.
So, how do we break things? In 2D, we can make 2 different versions of a sprite – broken & unbroken – and swap them out when they get hit, spawn some particle effects out, easy. But what about 3D Models? Well, in the modeling application we can make 2 versions of that same model one broken and one — I’m gonna have to stop you right there. We can do this much better – something faster, something less resource-heavy, and something that won’t always look the same twice. Let me introduce you to Voronoi.
Alright, so Voronoi is a mathematician, but what I want to introduce you to is an algorithm he developed, called the Voronoi Diagram. The TL;DR of it is, basically, given a set of points on a plane, we can partition the plane based on distance. The given effect looks a bit like shattered glass.
With this, we can manipulate 3D Models – in Real Time – to break apart in any way we wish. And, to do that, we turn to the Internet.
On Oskar Sigvardsson’s github, he wrote a plug-in & tutorial for Unity, and posted about it on Reddit as well, and it’s all completely free (just as long as he gets a little mention in the credits). On his github, he explains his methodology, as well as the research & short-comings he encountered along the way.
That’s not to say his code is completely perfect: he does mention that he ran into issues regarding the physics engine when too many “shards” began to pile up. The project is incomplete, but it should be a great resource for anyone who wants to take it a step further. And, to do that, I’d say go to…
Now, what we have here isn’t fracturing or destruction. In this tutorial by Alan Zucconi, we dive into the application of Voronoi in terms of shear math being used inside a Unity Shader. He explains how the fracturing is used in plug-ins like the Advanced Tools Mega Pack (formerly Fracturing & Destruction), and goes on to explain its usage in procedural generation and AI.
AI!? What? How can this be used in AI? You must be some kind of —
I’ve already made a long-winded A* Pathfinding Tutorial here, but this article by Brent Owens explains how some of the concepts of A* can be used with Voronoi Diagrams to procedurally create paths in changing environments. You can think of this as the back-bone to NavMeshing. With this, you AI Agents can navigate between obstacles, find the closest checkpoints, or find a dense collection of items!
Voronoi has a handful of application – not just for destruction, but for real-time action that can make gameplay experiences unique, creative, and fully immersive. Go and give these links a look, and, remember, have a blast.
Look, that was the only pun I made in this post – let me have the one, OK?