Pocket City Dev 5
The terrain was a little bland, so I decided to spice it up with nature.
To fill the grid up, I decided to implement trees. Created a few basic tree grid varieties and implemented it into GridManager.cs. However, this forced me to spawn all of the trees in the Start() function which causes a longer loading time, CPU spike and worst of all it makes it so that after the initial radius no more trees spawn. Increasing the radius exponentially increases the amount of trees being added (because each ring has more grid sections to cover). So i had to pivot.
I created a new Chunk Manager, split the main grid up into 16x16 chunks, and checked the player camera and only loaded the surrounding chunks. This makes trees spawn around the player continuously. However, this would become laggy as it would happen every frame.
Two ways I decided to prevent this:
- Check if the player had changed chunks. If it’s still the same chunk, early return to skip the entire code process.
- Check if the nature has already been loaded. Only load if not loaded. This obviously saves on time complexity, and allows me to have the freedom of creating varying tree density. It also makes it so that the trees do not regenerate constantly.
And that completes the visuals for now. Probably will add more foliage and other variety in the future, but for now this will suffice.
Finally, this has a severe performance penalty. To cater for lower-end devices, I added a toggle which will later come to a settings menu for ~4x the performance without impacting gameplay. Optimisations, such as chunkloading and LODs will be added later to increase the performance with trees, but that will come after the core game is finalised.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.