A couple weeks ago I worked on a game for the IndieCade Climate Jam. The task was to make a game that involved clean and renewable energy solutions. I found a team on the IndieCade discord and we decided to build a tiny planet type game called Planit.
The design involved a hex graph over a sphere that represented the planet. This was probably the biggest hurdle of the jam for me. When I first looked at how you would go about generating a hex sphere, I found math! A whole lot of Math! Since I did not think I had the time to really understand how you would generate a sphere like that, I tried to find other solutions. Ultimately I landed on using Blender and the “Mesh: Tissue” add-on to create a sphere made of hexagons/pentagons (I learned during this jam that you can’t make a perfect hex sphere, there has to be some pentagons involved to make the graph work). From there I separated the sphere out into 642 hexagon and pentagon game objects. It was not the most elegant solution, but it worked!
After I had a sphere made of hexagons/pentagons (or tiles), I was easily able to add things like rotation of the planet and MouseDown/over events. We also wanted a way to have each tile’s stats affect its adjacent tiles. What I did for this was to add a sphere collider to each tile.
When the game starts, each tile checks what is colliding with its own sphere collider, and adds the colliding tiles to a list. This creates our list of either five or six adjacent tiles, and then throughout the game gives us easy access to the adjacent tile stats. We then use these stats to update our tile based on its surroundings each second.
Once we had our tile and adjacent tile stat system set up, it was time to add buildings! Since I was working with a team on this project, I really wanted to make adding different types of buildings to the game as easy as possible. Since the goal of Climate Jam was to educate on green energy and climate solutions, we wanted to be able to store and display descriptions of our buildings, since that was where we were going to be doing a lot of our educating. So, for our buildings we needed a few things:
- A building name
- A building description
- A prefab of the building model
- Various building stats
- The upgraded version of the building
The way to implement this became clear pretty quickly, scriptable objects! Scriptable objects in Unity are basically data containers that can be easily accessed from code within Unity. They make it very easy to be able to set up a sort of database of in this case buildings, that can be added to or removed from super easily. Since we also needed a building upgrade system, we can use scriptable objects to reference another scriptable object very easily, so on each base building we would fill in the upgraded building field, which was just another building scriptable object. If that upgraded building field was empty, then we would just not show the upgrade panel in the game for that building since it was assumed to be already upgraded.
In our game, we only used one upgrade level, but these scriptable objects were made in such a way that we could easily nest building upgrades, and have a building with as many upgrades as we want without having to adjust our current code. Scriptable objects allow for a lot of this kind of modular flexibility, and I am really just scratching the surface of what can be done with them here. Check out the video below for some other really cool stuff you can do with scriptable objects:
One problem I ran into with the buildings was that I had nothing to really base their rotation off of initially. The tiles themselves from the blender model did not hold the rotation data like you might expect them to, so I had to come up with another solution. What I did was I just made a simple script that when spawned, the building would point its bottom to Vector3.zero, or the center of our sphere. This way all the buildings would be upright when spawned.
Next, we had to add research cards to the game. For this I also used scriptable objects! In this case, the scriptable object contained:
- Card name
- Card description
- Various card stats
- Card sprite image
- Building scriptable object, if the card is a card that spawns a building
In the case of the buildings, each building is instantiated with their applicable stats. For the cards, I just had 5 game objects in the scene that turned on/off and when enabled and had their stats updated based on the scriptable object of the card drawn.
The last bit of code from this project I’d like to talk about is how we made the world tiles randomized. For each tile, in start, there is a 1 in 40 chance that the tile will be set to a water tile. After that, we loop through the tiles, and if they are a water tile, then we make their surrounding tiles water as well. This ends up giving us a pretty good kind of continent generator with really simple code.
And that’s it! My first jam working with a team was a great success! We are planning some updates to the game in the future so more to come! Please check out the other work from my jam teammates:
Game and Narrative Designer:
Steven Denisevicz — Bonsai LLC — www.boncreate.com
Rosko Vair — https://roskovair.itch.io/
Environmental Advisor and Researcher: