Generate Random Terrain populated with buildings and tree in Unity using perlin noise
Click here to see the codeThe objective of this project was to create a randomly generated landscape that would be populated by trees and houses. Above the landscape, there would be a flock of birds (or boids as referred to in the code) that randomly fly around a 'leader' bird. This project was written in C# using the Unity game engine.
A couple of the major difficulties with the project were bird movement, collision prevention, object placement, and fractal noise generation. The bird movement uses splines which makes sure that the bird's flight patterns look smooth and realistic. The splines essentially use previous and current direction as well as velocity to calculate the required change in slope for the bird to reach its goal destination. The code for bird movement can be found here . Separation, cohesion, and velocity alignment were used to make sure that the flock stays together and does not collide with the terrain or other birds. All of these functions use a scanning radius that detects the position and direction of the surrounding birds to make an educated decision for the bird's next action. The code for these three functionalities can be found here . The terrain itself is modeled by using a random heightmap that is generated using a fractal noise algorithm. The height map is then applied to a flat surface using triangle mesh mapping to create the terrain. The variation of the textures is based on the altitude of the heightmap which is set using a custom Material in Unity. The last major challenge of this project was the placement of objects. Houses and trees cannot be placed on the water so a location that is not at altitude zero must be selected. Once the location was selected the slope of the mesh must be found at that location in order to rotate the object to realistically sit on top of the terrain. All of the code regarding terrain generation and objects can be found here.