Degree Project

This is where I document my progress for my degree project at FutureGames. The goal of the project is to create a dynamic game world with procedurally generated terrain, biomes, structures, and weather. Plus some creature AI and a sound system for fading in and out different ambiance based on where you are. In total I will use 10 weeks for this project, and the engine I’m working in is Unity.

Week 9 and 10

Since I didn’t have time to post last week I will merge last week’s progress with this week.

Updated loading screenIn order to make the loading screen a bit more interesting I added some bouncing trees.

Added Polygon Wind ShaderI wanted a shader that simulates wind in the trees to make the world feel more alive. But because I had no experience with shader scripting, and no time to learn it right now, I looked for a ready made shader.The one I found was Polygon Wind by the user RenanBomtempo on GitHub.

The shader did more than I needed so I removed everything except the swaying motion itself.

Added portalsI finally added the functionality for the portals that change the version of the island.When the player has added the same effect on ten or more trees, a portal will open up in front of the corresponding pillar. And if the player touches it the island changes.I also added beams of colored light coming from the pillars when the portals are open. This makes it easier for the player to find their way back to the platform.Since I decided to remove one of the versions of the island I also had to remove one of the pillars.

New sound effectsI added sound effects for the different effects, when a portal opens, when you step into a portal and wind sounds in the desert version of the island.

Updated weather and sounds in different versions of the islandThe muddy version of the island now has a permanent rain cloud above the middle, the desert has no rain at all and the default night sound does not play in the snow or desert.Small bounce effect when giving trees effectsWhen you touch a tree with an effect a small bounce animation plays to give the player more feedback that something happened.

2018-12-07

Week 8

This week I didn’t get as much time to work on this project as I would have liked. But I still got some things done.

Much faster loadingI made some tweaks and improvements to the generation of the world that makes everything load faster.

Made the coroutines do slightly more work each frame.

Waiting until the generation is done before turning on any other logic (like enemies and weather and such)

Removed one of the terrain copies and simplified the texture drawing somewhat.

Terrain generation modificationThe terrain generation got a slight modification that makes the mountains be taller and the valleys be flatter.

Stones on sandAdded small stones on sandy ground.

Hide foliage and leaf particlesFoliage and falling leaves now gets hidden when changing to the snowy or dry versions of the island.

Wind particlesTo make it more apparent which way the wind blows I added some particles that fly in the direction of the wind.

2018-11-30

Week 7 – A week of many things

Since last time I made many small additions, some fixes and a bunch of busy-work that was really needed.
For some reason though, this week’s build has a way too long loading time. In the editor it’s also a bit longer than I would want, but the build more than triples the time. It will be a priority for next week to try and find a solution.

Small change to loadingI added a queue of IEnumerators that that automatically starts the next one in the queue when it has finished. It was just a small change that made the loading of all the systems easier to keep track of. It is also easier to add new things to load now.

UmbrellaA small cosmetic thing I added was an umbrella that can be picked up. The only thing that it does is change the sound of the rain around the player. It worked adds something to the atmosphere.

RunningAfter walking around the island for what feels like the 1000th time during tests I decided to add a running mode when holding shift. It will probably only be available as a debug thing. The speed increases the longer you hold shift up to a point.

Improvement on flocking creaturesI made the flocking creatures not walk through obstacles. They now check a sphere in front of them to see if there is any colliders that of the correct layers blocking the way. If so they start turning.

New tree-prefabsSince I needed to remake all the tree prefabs anyway in order to be able to change the tree meshes based on which version of the island that is loaded, I decided to also use LOD-versions of the meshes to increase performance.The new prefabs all have three versions of the same tree, one green, one dead and one with snow. All of these also have three different LOD levels

Work on the “gameplay”This week I started on implementing the gameplay of picking up effects and transferring them to the trees.As I mentioned last week, the idea is that the player chooses which effect they want to put on the island. And when enough trees have been given an effect, a portal will open up in the middle of the five pillars. If the player then steps through the portal they will be taken to a different version of the island.

More structuresI added two structures that can spawn in the world, a well and some stacked stones. Both with unique ambient sounds. I also made the tower and the field be spawned by the same ObjectManager as all the other structures, since they were special cases before.Aside from that I made sure that every structure has an effect that the player can get.

More versions of the terrainI added three more versions of the terrain, making the total five. Default, snow, muddy, dry, and dead. Each of these are copied from the default one, but has unique materials that I paint on with a coroutine. Unfortunately this is bad for the loading time. I will try to see later if I can optimize it somehow.

Effect particlesI created two different particle systems for the effects. One when the player picks up an effect and another when a tree gets a new effect. Both get colored based on which effect it is.

New simple creatureTo increase the number of ways the player can get effects I added a creature type that gives the player an effect when touched. They are basically colored cubes that roam the map with colors corresponding to the effect they give.

Functionality for shifting between versions of the islandFor testing purposes I added an event that fires when pressing 1-5 on the keyboard. These buttons switch between the different versions of the island. All the trees and the terrain are listening to this event, and hide and show the correct meshes.In the end this event will only fire when the player steps through the portal, but it’s a great way to test the functionality.

2018-11-23

Week 6

This week I made some enhancements to the code, added some small features and planned and prototyped some bigger features.

Better loadingIn order for the loading bar to be accurate and take every system into consideration I first created an empty scene that starts the loading. It applies the loading progress of the main scene to the progress bar. When the main scene is loaded, the generate terrain script starts a coroutine that moves the vertices of the ground to the correct height. Every 500 vertices the coroutine waits for the next frame and updates the progress bar.When that is finished, the next coroutine starts and instantiates a certain number of objects each frame in the same way. This goes on for each system, foliage, trees, paths etc.This way the progress bar gets constantly updated and Unity doesn’t get bogged down trying to do too much on a single frame.

Different textures under treesI added functionality to paint different textures on the ground under each type of tree to add some variation.

Change ambient sound at nightWhen deciding which ambient sound to play I added an extra check to see if it is night or not. In the earlier version I just checked if the player is standing beneath a rain cloud.

Better spawning of cloudsMy earlier system for spawning clouds just instantiated all the clouds on the same frame. Now I made it so that when it’s time to spawn a new batch of clouds they spawn one each frame.I also removed the variable windDirection and instead use the forward vector of the cloudManager object itself in order to make it easier to change the cloud direction.

Prototype of ”gameplay”I also thought a lot about the gameplay of this little game. It’s basically just walking around on an island at the moment.To change that I added a sort of platform with five pillars that spawns somewhere on the island. These pillars are indicators of how much the player has changed the game world. The idea is that when the player stands close to different structures and objects they are are imbued with different effects. If they touch a tree while having an active effect the tree changes hue slightly and the corresponding pillar lights up more. After enough trees have been changed a portal will open up on the platform, and based on which pillar has the most trees the portal leads to a different version of the island.The planned versions are: cold, lush, dry, wet and dead.Each of these will keep the terrain shape, the positions of trees and paths and structures, but will need different textures, tree meshes and creatures.

Multiple copies of terrain meshIn order to save time when generating different versions of the terrain I had to make some changes to the generation.The PathPainter class now draws on a separate RenderTexture so that I can reuse the same paths on multiple terrains without having to generate them again. And I have a unique material for each version of the terrain that has their own RenderTexture for the ground color, but shares the path texture.

The five-week mark

As of right now I have used up five of the ten weeks for this project (minus the time spent looking for internship, making work tests and having interviews). And I think it is time to describe the different systems I have made.

Terrain generationI based the terrain generation on the old island prototype I made for a Unity course. I loop through every vertex on a plane and use Perlin noise to move them up or down to create hills and valleys. The further from the center a vertex is, the more it is pushed down in order to always make islands and hide the edges of the plane under water. On each startup I randomize a new seed.

Trees and biomesBesides making the terrain itself I also spawn in different types of trees based on different “biomes”. These biomes are, like the terrain, generated from Perlin noise but with a much lower frequency.

FoliageI made some grass and flowers from simple planes with alpha channels. These then gets spawned randomly across the terrain. In order to reduce performance cost I cull the foliage layer 150 units in front of the player. I might have to tweak this value since there is some visible pop-in.

Dynamic weatherIn order to make the world seem more alive I’m working on a system to spawn clouds and rain clouds and make them glide across the sky. I spawn in prefabs with multiple cloud meshes in a random pattern on one side of the island and let them move according to a global wind direction vector. From time to time the wind direction changes slightly, and all clouds are affected.The rain itself is made from multiple particle systems.

One for sheets of rain that uses a texture, one for single rain streaks, another for small particles that creates square splashes on the ground on impact.

Dynamic soundEvery biome has an ambient sound effect associated with it that fades in when the player gets close to a tree of that biome. In my SoundManager script I use one Audio source for each biome sound and fade the volume of these based on which biomes are around the player.

Day-night cycle and post processingThe sky above the island is a prefab that has three parts: The sun, the blue sky and the starry sky. The whole prefab rotates slowly around one axis.

When the sun gets close to setting, the fog starts changing color from blue to orange to black at the same time as the blue sky starts to fade out and reveal the starry sky behind. The process is reversed at sunrise.

Placement of pathsThe paths are created by a script called PathPainter that is attached to a game object in the world. The script has as a goal to create a set number of path pieces on the ground while still adhering to certain rules. It takes a random spot on the map and paints a path texture on it and pushes the vertices down slightly. From there it rotates a small random amount, moves forward and repeats the process of painting a path piece. If the height of the terrain is too high or too low, the PathPainter aborts the current path and tries again somewhere else.I also instantiate random rocks on the side of paths as decoration.

Foam particles and falling leavesSome of the trees has leaves falling from the branches. These are simple particle systems placed in the tree prefabs.To create a simple effect for foam on the water I use a particle system that follows the player and creates particles at sea level.

Creatures with flock behaviourIn order to populate the world with more than plant life I created some creatures with basic AI.The first of these was a small flocking creature that hops around in groups and gets scared if the player gets too close. For these I used a simple algorithm for Boids made for schools of fish. I modified it to work in only two dimensions and based the y-values on the terrain height below the creatures.

Randomized placement of structures and objectsAnother thing that makes the world a bit more interesting is the spawning of randomly picked objects and structures at different places. These all have their own rules for where they can be placed, and the world generation script just calls a function in the object to get a valid position to place it.
As of now the objects that generates are: a windmill, a tower, a stone circle, a field of wheat and some ruins.