Trying to Make Terraria in One Week | Unity Game Devlog

i gave myself one week to recreate terraria entirely in unity my discord said they couldn’t tell the difference my goal for day one was to get the basic terrain generation working so i could generate some caves some terrain on the surface and also have all the tiles working this didn’t go as planned i ended up spending day one mainly setting up the name spaces in the project architecture and i also spent countless hours setting up the rule tiles it’s a bit ridiculous how many sprites terraria actually has uni makes it easy to extract sprites from a sprite sheet which was really handy but then actually importing them into a rule tile took some time and defining all the rules as well something i didn’t know initially about rule tiles was their extra little functionality where you don’t have to define a rule for each direction a tile can face you can just define one and tell it to rotate based on its surrounding which is quite handy i didn’t know unity had that ability until i read through its actual documentation because i needed a custom tile so that i could get the stone and the dir and grass to connect to each other rather than staying separately and it also let me define special tiles so for example when dirt and stone connects it can use a different sort of tile to avoid the choppy sort of transition between stone directly into dirt the goal for day two was to finish off what i couldn’t finish in day one which was getting the basic terrain generation working so i got that work the caves were generating the terrain was generating nicely as well and i also added the background rule tiles so i could get some walls to cover up the empty gaps in where you could see the sky i’ve done this sort of thing many times before so really it was just kind of doing the same thing again but a little bit better i moved all the data and the settings for the terrain into scriptable objects that way i can easily drag and drop whichever terrain settings i want into the terrain generator and it would use that although i am only using one method of generation for this project it still lets me make the whole thing expandable and also keeps my editor nice and clean day three was one of the days i was kind of dreading uh because i knew i had to add alls and add-ons and trees and whatnot onto the terrain to make the game feel a little bit more lively but i also knew that it would not be as easy as it sounds the awes was relatively simple just using pearl noise to determine where the oils are placed and each all sort of calculates that itself and i can just read that and place the relevant off in that tile the trees was where i struck a little bit of a hurdle because although yes generating a tree is relatively easy terraria actually has branches and roots for the trees to make my life easy i ended up just using rule tiles so i can just place a leaf next to the trunk and if it connects with the trunk then it can just switch to the leaf branch sprite for example um this worked well in the editor when i was just testing on a term but when it came to generation it ended up connecting to the wrong tree to fix this i used a bit of a crude fix where i just said okay if there’s a tree next to it don’t spawn a tree there that way you can’t have two trees next to each other and although that’s a bit of a band-aid fix it did the trick and i was ready to move on anyway day four was gonna be the day which actually brought everything together so i was doing the lighting and the lighting was relatively easy to do i use minecraft system of lighting so every block has a light value between 0 and 15 15b obviously the brightest and 0 being the darkest i would then start the calculation at the top of the world and move block by block down and every block that was a sky block would set to the max brightness and every time we hit a solid block would negate the brightness by one every time we hit a background wall block then would negate the light value by 0.5 for any tile it encountered in that calculation that was meant to illuminate which was a light block for example a torch it would then set the light value to the max brightness again and this works pretty well the issue was that if i’m rendering in only one direction then any blocks above that light source would still be the color it was meant to be because it doesn’t take that into its calculation so then i did the same calculation in reverse and this got me the basic light map where it was just black and white textures because it’s either gonna be max brightness or not gonna be max brightness or something in the middle but this didn’t take into account adjacent tiles so all i had to do was check the neighboring tiles and set the brightness of each tile to the brightness of its brightest neighbor subtracted by one or whatever i was meant to subtract it by i then optimize this by chucking the whole calculation into a co routine which lets it run on a separate thread having minimal to zero impact on the overall performance of the game which is exactly what we want since it’s doing the calculation for every tile in the world world plus it’s adjacent tiles times two because we’re going in both directions so realistically if we have a 300 by 200 tile world it’s doing it 300 times 200 times 4 times 2 calculations and to run that all on a single thread would be ridiculous but i didn’t want to jump into chucking it into a compute shader which is actually a better way of doing the whole calculation anyway after day four i was starting to get a little bit tired but i knew that i also needed to add liquids and a water simulation to the game so day five was spent by adding water and lava into the game there wasn’t much of an issue with these the whole system actually works pretty easily again in a separate thread where each tile just checks if it should or should not propagate the water into its adjacent tiles and each tile that does spread does the same check and this system is basically recursive and since each tile does its own calculation on the separate thread it has pretty much no impact on the performance and i can simulate as much water as i want and while the water is simulating i can still do other things in the game such as update the lighting or break blocks and the reason i needed that to work is because when i was adding lava i needed lava to update the lighting each tile it propagated so that way it illuminates the area as it flows which has a pretty good effect actually overall [Music] by day 7 i had implemented most of the features i was planning to add but there were still a few features which i just knew that i didn’t have enough time to add in my assigned time frame so i had to cut out some of those features and hopefully one day i’ll come back to the project looking through the sprites i actually downloaded terraria has a lot of stuff for the player so i think it would be actually really cool to be able to add something like that as well as a basic inventory for them to be able to run around and collect some tiles for those interested in downloading the project it’s currently not available anywhere but i will be uploading it to patreon where tier 2 patrons can download it and mess around with the code as they wish [Music]

Download my Complete 2D Gamekit here:
https://erensoftworks.itch.io/erens-complete-2d-gamekit-for-unity

I got bored and tried to remake Terraria! Join me as I try to code one of my favourite games in one week.

✅ Join the Discord : https://discord.gg/K4fQ6s82Q4
🧡Support the channel: https://www.patreon.com/erenmakesgames

00:00 – Introduction
00:06 – Day 1 – Terrain
01:10 – Day 2 – Trees & Ores
01:47 – Day 3 – Get Stuck
02:46 – Day 4 – Lighting
04:44 – Day 5 – Liquids
05:45 – Summary
06:10 – Download

Note: Sprites seen in the video aren’t included in the Patreon package (cause copyright 😀 ) However, all info is within the project files as to how to setup the ruleTiles with your own sprites!

#devlog #unity #gamedev

30 Comments

  1. Update: Coroutines don't run on a separate thread! Thanks for all the comments! As I'm sure you understand, I'm still continuously learning as well! 😀

  2. That was all to fast and briefly but that’s probably the whole point. I like to know how the light works…. How do you make the lightning? Do you tint the sprites? Draw over them? Shader? How does the lightning map work? And everytime you place and remove tile you calculate the whole lightning map new or just the neighbors? And then the neighbor neighbors? Hooooooow?

  3. my brain died trying to think on how ur computer didnt explode for this. i tried making lighting to my own sandbox test i have been making and my co puter fries XwX

  4. You just helped me make my game that im working on so much better plus i added the way you handle light! I was kinda thinking of stopping the project cuz i didnt know how to implement light but i found that video THANK YOU!!!

  5. Доброго времени суток, можешь пожалуйста сделать туториал 2D Water в Unity, чтобы она реагировала на объекты и вела себя реалистично?

  6. Could you perhaps do a tutorial on this? I know you've done a sandbox game tutorial series before, but it would be interesting to have it revisited, this time using a tilemap instead of individual gameobjects, and the game i'm working on is similar to terraria in terms of world styling

  7. Hey great devlog! Quick question, how did you get the rocks and dirt to seamlessly connect like you have in the video? I cant find any good resources 🙁

    Also does your patreon still have the project files for this project? I would like to know how you did all that cool stuff…

  8. Wow that's a really nice work! Btw can you also make a tutorial on how health regen in terraria works like it starts off slowly and then speeds up as time passes upto a certain limit and resets when player gets hit? That would be really cool 😀

  9. Great video !
    How did you manage to connect the dirt Rule Tile and the stone Rule Tile together avoiding awefull transitions ? I think you have separate Rule Tile for dirt, stone, grass, ore …

Leave A Reply