Trees are a pretty important part of the core gameplay system of Manifold Garden. After all, trees are the source of the cubes, which are used to solve puzzles, bend water, and grow more trees.
Here are some of the tree designs:
All of the trees above were made by hand. You can see that the same tree repeats many times. I was originally planning to make 100 trees by hand. I made about 4, before I realized that process was not fun and also super tedious.
Here is how I used to build trees:
Like the old ways of building stairs and windows, it involved using ProBuilder and building each separate component, manually sizing and placing every segment.
Some people have asked “why not just create a set of 10 trees or so and randomize their placement?”.
The reason is because the volume of the tree matters a lot in a level. If there are only a set number of trees, I would actually have to design the level based around their volume, and the specific needs of trees vary widely from location to location.
A much more typical process for me is I’ll design a level, and then go: “this area needs a tree, but it needs to be 20x40x20 in volume, because of the setup of the level”. If I just have a fixed set of trees to choose from, it’s highly unlikely I’ll find a tree that’s exactly of that size.
Also, using a fixed set of trees can get pretty obvious to the player.
Anyway, the trees do follow a very specific ruleset in their look, so there’s really no reason that the process can’t be automated.
David and I decided to make a tree generator for this.
As you can see, it takes a lot of input. You can choose the probability for growing upwards, the probability of a trunk or branch splitting into two, the range for each segment (vertical or horizontal), etc.
The red outline box is the tree boundary, and the green outline box is the trunk boundary. The idea is that the trunk would never grow outside of the green box, and the tree would never grow outside of the red box. They’re kind of soft boundaries (especially the red box as the leaves can go past the boundary). However, it’s pretty easy to tweak, which is part of the tool design.
You hit “Generate Tree” to create a tree, and then if you actually want to make it a tree in the game, you hit “Actually Create Tree”. This allows me to go through a bunch of variations to pick out the one I need, which is really great.
Once the tree is generated, it’s actually all in separate parts, with each branch parented to the one it grew out from, so it’s quite easy to edit (or should I say… prune?) the tree and tweak it till I get exactly what I want.
It also saves the seed value, so you can always go back to the base design.
Here’s the tool in action:
The key with the tree generation algorithm is that each segment uses world coordinates to determine the direction. So the y positive is always up. This was thanks to David.
I’ve done some procedural generation with fractals before, and always used local coordinate systems, with each object passing on its rotation and position with relation to its parent to the next object. In this case, none of the objects had a sense of the objective up, only in relation to its previous object. This would actually have been pretty complicated, involving passing on rotation with matrices and all that.
Using the world coordinate system worked out quite well in this case and made the algorithm a lot easier to manage and piece together. It works in this case because the trees do have a sense of “up” when growing.
Anyway, what I love about the tool is that in the time it used to take me to make one tree, I can go through hundreds of design in the same time.
Once the tree is built, there still needs to be some processing done to make it work in the game. Of course, I made a tool for this as well . That will be in the next update.