• Register
Post news Report RSS Using a cellular automaton in video games

An overview of how we are using a cellular automaton in Nanotale, the spiritual successor of Epistory, to simulate interactions between various elements in a fluid-like simulation.

Posted by on

Cellu-what?

It’s a way of simulating a world using a divide and conquer strategy. Instead of having a massive “World Simulator” it’s often easier to simulate each object when making a game, This strategy goes further by dividing the world into uniform cells. Each cell has a state and a set of rules to change, if possible, into another state. Cellular automata are used in a very wide range of scientific domains, including computer science, mathematics, physics, and many others. The most famous is probably Conway's Game of Life, it has only four rules and two states and you can already see a lot of patterns emerging from its simple concept.

There are numerous ways to use them to create interesting systems in games, too. If you see liquid or gas simulation you probably encountered a cellular automaton in game form. But some games go a step further and base most of their gameplay on elemental/physical/chemical interactions. Although I can’t be certain they used one, Oxygen Not Included, Noita & Creeper World are fine examples of what you can accomplish with this kind of system.

Poison(green); Fire(orange); Water(blue). One of the spheres spreads poison, the other spread fire. Taken from an old prototype.

Poison(green); Fire(orange); Water(blue). One of the spheres spreads poison,
the other spread fire. Taken from an old prototype.


Why do you need one?

When we started thinking about what to do for Nanotale, we wanted to improve on the puzzles and have a bigger variety of spells that the player could use. The limiting factor here being the keyboard, we can’t use the same kind of interactions as more classical games will ask of the players. It would quickly devolve to QTE instead of, for example, a skill mastery.

Since we’re reusing the camera angle of Epistory, top-down, we have a good view of the ground. We had the idea that the spells could be affecting the ground itself. Hurl a ball of poison at an enemy and it should create a puddle of poison where it landed. Other enemies would walk on it and get poisoned too. One thing leading to another, we reached a point where all logical interactions between elements and objects should behave in a “realistic” way, as defined by the game’s world rules: a typical cellular automaton use case. On top of that, it creates a lot of opportunities for interesting puzzles and strategic combats. A few examples of interactions: fire burns poison, life transforms poison into water, poison propagates in water... We’ll dedicate a full article to element interactions later.

What form does it take in Nanotale?

Although we can argue that all systems tend to reach equilibrium, in Nanotale, we wanted the system to work in a burst of activity and quickly stop. All the rules are designed to go back to stability as fast as possible. It makes the game easier to read for the player, one or two interactions at a time. By the time the player can make another domino fall, at least one reaction is done.

That stability is also beneficial to puzzle setup, the layout will stay as the designer planned it until it is disturbed by the player. This is as opposed to more complex simulations that would start the reactions as soon as the game begins because such games take into account a lot of parameters like pressure, temperature, and other physical or chemical reactions. We kept the number of parameters low, to make it a bit less of a simulation and a bit more of a rich puzzle environment.

Everything working together. Remove the poison, create an ice bridge.

Everything working together. Remove the poison, create an ice bridge.


How does it work?

As stated before, the first thing to do is divide the world into uniform cells. In each scene, the designer can define a zone where the cells have to be created. Since we’re taking the “puzzle” approach, we don’t need the whole world. In these zones, we divide them into an array of cells. It will also allow us to prepare all the data we need to actually use the system, such as initial element, texturing & shader info.

58 logos

Here you can see the cells once they are created. We plan to optimize the colliders away.


The cellular automata are not the only thing interacting with elements. Most objects in the world will have a reaction to at least one element. We also sometimes regroup cells together to make something new. Instead of simply changing the state of the automaton, we can generate a new platform or something to prevent enemies from reaching the player.

55 blocking ice logos

Ice(light blue volume); Water(blue). Creating a blocking mesh from water cells hit by ice element.


So, what does a cell do?

There are a lot of cells, tens of thousands, in the game world so the goal here is to make the cells as small as possible and more importantly, execute as little code as possible. Once a cell receives an element, it will wake up, process the reactions it should have to it, sometimes handling timing or a transitional state. For example, poison cell receives life element. It becomes a life cell for a time and transmits the life element to its neighbors. After some -short- time, it becomes a water cell. Once that’s done, it goes back to sleep until something disturbs it again.

69 propagation spells

Poison(green); Life(light green); Water(blue). Reacting to spells sent by the player.


It is one of the main difference compared to more traditional cellular automata, most cells are sleeping, waiting for the next piece of work. It allows us to have relatively heavy duty cells since as most of them are sleeping, the active ones have more processing power available.

Conclusion

It’s the first time we have built a system with this level of complexity. I had to learn a lot of new concepts to make it work and it was worth it. That kind of technology has an enormous potential both in terms of visuals and in terms of gameplay. I’m sure we’ll see more and more games using cellular automata as a core part of the gameplay, not just to make things prettier.


We’ll come back later with more details on how it works once we get further in development and the paint had some time to dry. There’re a few topics left to talk about, especially around how we render the elements. Don’t hesitate to ask more detailed questions in the comment, and don’t forget to wishlist Nanotale - Typing Chronicles on Steam!

68 propagation plants logo

Same concepts but activated by objects in the world...


Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: