Creating An Ecosystem Simulation Game In 6 Months

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
six months ago i began working on an ecosystem simulation game i honestly don't know where to begin but the inspiration for this whole adventure started with this single individual this is charles darwin in 1835 he sailed on the hms beagle to the galapagos islands to document observations of the surrounding ecosystem what he found there was rather shocking and completely transformed traditional beliefs you've most likely seen this image somewhere already it's a famous illustration of the finches darwin observed on the different islands in the galapagos now what i want you to do is instead of focusing on the birds i want you to think of the overarching system what caused the finch's unique beak shape well that's a simple question it's really just what they ate the beak shape was specialized for the food the finches ate like the insect eating pinches or the seed eating ones now what caused the environment's unique characteristics this question is a lot harder one could argue that the insects on the island only colonize in areas not near the semi-arid lava substrates thus making a divide or border between the parts of an island where insects reside one could also argue that the prevalence of rotten wood due to humid environmental conditions allow mangrove and woodpecker finches to dig out beetles inside the wood using cacti nevertheless this story of the uniqueness and dynamic nature of the ecosystem is what i wanted you to get out of this story this story shows that each segment of the ecosystem influences each other in significant ways that you didn't even think of as you could probably tell i was highly intrigued by this so i set out to make my own ecosystem simulation game [Music] [Applause] excited to start the project i first created a small test creature that looked like a cube this creature would be the prototype for the basic mechanics of the simulation and once i created the creature script i added a couple lines of code i placed it on the ground and let it run [Music] as shown this creature wanders in a random direction and its direction changes every second after spotting a piece of food it picks the closest one rotates towards it and devours it [Music] that was a great success but we're still very far away from making anything like a simulation plus this creature is just a cube so let's change that first here's what i'm gonna do each creature will consist of four parts a head neck torso and leg the head will serve as a distinctive identifier to test multiple creatures you can use the head shape to analyze different species next the creature's height is influenced by their necks as an example if the plant is taller than the creature the creature will not be able to consume it and lastly the creature's torso changes the amount of storage for food and then there's the legs for the legs it's going to be a lot more complicated i'm going to use something called inverse kinematics to move the legs inverse kinematics will allow for an endpoint of an arm to move to a designated position in the context of humans when we're walking we first step forward a known position away from our torso then once our back leg is a distance away from our torso our back leg becomes our front leg this cycle repeats and you've got the basic mechanisms for walking for the game i can set four target points attached to the torso then i can set a distance to which the leg goes back to the new torso position and finally take the average leg y position and set it as the torso y position i know that was a lot but it finally works [Music] after i finished that i spent a bit more time putting it all with ui and now you can select the creature you want but we're not done here yet you see the parts you can see on the creature are actually controlled by genes in the background what gets shown is the phenotype and what is behind the physical body is a number also known as the genotype for now i created eight genes in the form of an array which gets passed down to the next generation and here are the genes after all the genes are ready then we calculate three values first is the energy output which is mapped by this equation [Music] next is the total weight a weight value is associated to each part of the body after which it's added lastly is the total height which is just the height of the creature and after a bit of code here's what it looks like [Music] now it's time to make some plants for the ecosystem but before we go any further i want to talk about something very important [Music] a lot of the time we assume that the plant population is just there for a food source so the creatures can compete for it while this is perfectly okay to show experiments in a controlled manner it's also a very dangerous assumption plant populations can also evolve to resist herbivores the same way that prey can evolve to resist predators often times in the cycle of co-evolution like the name suggests intertwining populations of species can influence each other which may lead to a deadly arms race between the two species one example of this occurring is the lodgepole crossbills relationship a lodgepole pine is a tree that produces seeds with a hard outer cone and crust spills birds who use the seeds inside as a food source the problem is it's a conflicting point of interest if the crossbows successfully eat the seeds the crossbow population increases but because the lodgepole pine seed is used to pass life onto the next generation the crossbow decreases the chance of a lodgepole to successfully reproduce thus decreasing their population over time if the lodgepole population were not to resist the crossbow's effortless attempts at eating their seeds they would be extinct instead in the process of natural selection the logical pines with the thickest seas were able to survive and reproduce because the crossbows were unable to open the hard shell it was encased in and thus be able to resist the crossbow's efforts of sealing the seeds over time trees with the thickest seeds would survive and reproduce and the crossbow population would struggle due to the thicker seeds resulting in crossbills with larger and stronger beaks to survive and reproduce which then causes lodgepole pine cone to be even thicker where the cycle continues again while this is a rather obvious example of co-evolution what i want you to get off this story is the dynamic nature of the ecosystem in this example the plants were able to fight back against the herbivores and hold on tenaciously and this is exactly why i started implementing a more procedural and dynamic system for the plants the plan is to generate plants the same way we generate creatures previously and allow for some interesting scenarios to play it out between the two to begin with the plants i found a handy tool for generating procedural trees and decided to use it the tool already has 10 values like recursion level trunk thickness and much more inspired by the crossbills example i also decided to add two more genes seed hardness and seed armor these two jeans are rated on a zero to one scale one being hard and zero being light same with the seed armor essentially the plants will be generated using these parameters as genes and there are four types of plants ones with toxic seeds fruit seeds hard seeds and flying seeds each of which has their drawbacks and advantages two values are then calculated energy consumption and water consumption the idea is that the wider and taller plant will be able to gain more energy faster and thus be able to reproduce faster but take up considerably more resources and thus need more space on the map conversely a smaller plant will reproduce slower but be able to cram more plants inside what we expect to see is logistic growth where initially plants will exponentially increase due to the amount of space available but then start to plateau at the carrying capacity so i implemented just that and after a lot of work we have our first prototype of the editor [Music] now i made an editor for both the plants and animals i would love to finally start making them interact but the environment looks less than pleasing so i looked into procedural generation procedural generation will allow me to create hills valleys and coves with just code so i decided to follow a tutorial series on procedural generation by sebastian lag and made something like this yeah it didn't look great but i promise i fixed this later i then put the animals and the plants together the first problem was to figure out how to actually make the creatures move to the plant which before it was working but with the new creature there were a lot of problems [Music] eventually i got it to work and here's how it works [Music] the creature first wanders in a random direction in hopes of finding a plant when the physical distance between the creature and the plant is less than the look radius the creature will then move towards the plant the creature will then fill up its storage with the food from the plant decreasing the size of the plant once the creature is satisfied as shown in this equation the creature will then go find a mate when spotting a mate the creature will then walk towards each other and have an amount of maximum kids shown in this equation the child will then take the average of the parents genes then mutated by a specific amount specified by the mutation strength in the mutation chance value then the creatures will disperse and repeat this cycle until a predator appears a predator will chase the creature when in sight and when close enough it'll start attacking the creature to balance the predators each creature will have a defense and an attack statistic the attack statistic favors small and vast creatures while the defense statistic favors large and heavy creatures to visualize the attack prey will lose size over time eventually these two creatures will have to duel it out where either the predator runs out of energy or the prey falls and dies well now we figured out that it actually works so why not test out our simulation one thing i found super interesting was that every time i ran my simulation the creatures would either die out with a look radius and speed would skyrocket it seemed that the ecosystem selected for super high speed and super high look radii which made no sense to me since the energy cost function clearly didn't support that it turns out the look radius wasn't clamped so it would cover the entire map also it turned out that the creatures traveled faster when there was a larger look radius basically inventing teleportation [Music] i was genuinely surprised by this novelty and patched this loophole but it was still cool to see the simulation show something that you never knew in other simulations the gestation would just drop below zero i never knew this was possible and why would work in the first place but after looking at the code these creatures found a cheat code in the code the amount of children reproduced is stored in a for loop when the maximum offspring is less than zero the variable i will always be greater thus pretty much guaranteeing infinite babies if that happened in real life that would be pretty problematic so i fixed these loopholes and the simulation finally worked but for me the simulation visuals just aren't cutting it like i said before the procedural terrain is well it doesn't look too great so i decided to give the entire game a visual revamp [Music] finally it looks like something that's more visually pleasing so now the basic rules of the sandbox were finally finished it was time to run some more in-depth simulations the first couple hundred simulations were just a test to see how long i could keep the ecosystem running for with the plants unable to change in the creatures mutable i've also exported all the data into a csv so the data was easier to analyze most runs either completely flopped or the creatures became too powerful so the plant population died and the creatures followed soon after until about run number 89 when i increased the trunk size a bit larger so the plants could gain energy faster that i finally got two cycles [Music] now let's break down this run what we should expect to see according to the lock of volterra equations is something like this while we do see something like that in the creatures the plants not so much this is because i made the trees logistically increase the model only works if the rate of change is proportional to the population we can clearly see this in the herbivores because as a number of herbivores increase the easier it is for them to find a mate and reproduce however even though there are more plants if four to five plants depending on the statistics are near each other the next plant will not have enough energy to reproduce or survive and thus die i then ran a bunch more simulations to see if i could get the ecosystem to continue even longer and after more than 20 runs run number 115 i got three cycles now you may be wondering why this didn't go for any longer and maybe i could have gotten four cycles it's because the creatures got too good at surviving if we take a look at the data itself we can see that the storage and reproductive urge decreased over time showing a preference of food over reproduction we can also see a massive decline in size this is probably the most conclusive evidence of the eventual extinction of the plants decreasing your size allows you to decrease your energy cost and be more efficient with resources so when the plants started to increase again the creatures were quick to take advantage of the plants so before the plants could get to the carrying capacity the creatures had already eaten all the plants now it's time to add a predator for this it was much harder and i never got a clear answer some runs were odd to say the least and others were just one cycle i tried nerfing the predators but that just made them too weak and making them more powerful just ruined the experience for the prey however there's a reasonable answer we can expect here we can expect the plants to diverge from the prey and just have the predator and the prey interact while the plants are at maximum saturation this is because assuming ample food for the prey the predators will eat the prey when too large increasing the total number of plants then the prey and the predators should assume predator prey dynamic mentioned earlier until selective pressure selects for better species after which an arms race will begin between the two species or one will wipe out the other
Info
Channel: Fun Master Ed
Views: 470,302
Rating: undefined out of 5
Keywords: game development, gamedev, devlog, ecosystem simulation, simulator, simulation, simulation game, ecosystem simulation game, gaming, evolution simulator, evolution simulation game, unity game development
Id: 52ZeHGGEf6o
Channel Id: undefined
Length: 16min 28sec (988 seconds)
Published: Tue Jul 05 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.