This was the first week of my master’s course where we had the Procedural Generation lecture. The lecture itself focused on explaining the assignment and giving details on approaches for how procedural generation is created.
This week we were given a task to research approaches and algorithms for a procedural generation along with an attempt to create generation. Seeing as though the last time I investigated any procedural generation was in 2019 when I wasn't a competent programmer, my confidence in this task was low. However, I decided to have an attempt and be aware that one of the things I struggle with is knowing where to start, I made it a goal to just code something and see how far I can go from there.
My Attempt
I first started with the spawning of a grid and allowing the size of the grid to be changed within the Unity Inspector. I then set up a start and end point that is randomly selected when the button is clicked. Below is a video showing the generation of start (red) and end (blue) cells on a grid before the random generation was added.
Once I had a start and end point, I decided to have connected cells be able to change colour as a generation of a path. I started by collecting a list of the neighbouring cells, keeping it simple by only focusing on the 2 to the side and the ones above and below, if there wasn't an available cell, I simply put null, so the code is aware that nothing is there. After I got the neighbouring cells, I programmed it to pick a random direction and move one along and turn it black (randomly choosing again if the option is unavailable. This would end the desired number of "rooms" generated.
Looking at the attempt in hindsight, I am not sure what I was trying when I added the end cell as I had no intentions at the time to make sure it generates a path to the end. I also discovered a bug in my code where a neighbour can backtrack and count that as creating a new "room" therefore making it very hard to reach the desired amount. With all this in mind, I am happy with the initial attempt as it was without prior knowledge and as I would later find out, I had some of the right ideas but I was using them wrong.
Following a tutorial
After working on this unresearched attempt, I was informed by a classmate that we are allowed to copy tutorials for the tasks as we can look at the code and find out what they did and try to learn from it. This led to me creating a second Unity scene in the same project and creating new scripts that followed the Cave Generation using the Cellular Automata tutorial created by Sebastian Lague.
With this tutorial, a grid is made and then each cell is generated to be either black or white dependent on a seed which can either be created by the user in the Inspector or a random seed which is impacted by the current time. The visual representation of the map is done using Unity Gizmos.
The finding of neighbours is used to smooth over the map instead of the generation of cells.
Reflecting on coding
As previously mentioned, the last time I looked at any type of procedural generation was 3 years ago when I lacked knowledge of Unity programming which made my confidence in the topic low. But after creating 2 grid and cell generations with different amounts of knowledge, I am more confident in my problem-solving abilities and am excited to continue learning about procedural generation. Moving forward, I plan to research different approaches and attempt to make my versions of algorithms.
Comentários