I Made a Factory Game in 20 HOURS!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome i'm your code monkey so here's the story a while ago i was playing dyson sphere program it's an awesome factory automation game similar to the likes of factorio or satisfactory i even made a game that review with some interesting game design lessons so i was playing it a lot and i thought well why don't i try to make my own mini factory game it's one of my favorite genres to play but i never actually made my own so that's exactly what i did try to see how fast i could make the simplest version of the genre in total i worked on this minigame for about 16 hours and i'm quite pleased with the end result it's got all of the base mechanics you would expect as well as a nice amount of polish after watching this video you can go ahead and play it for yourself on the steam app it did involve some interesting challenges that are specific to this genre which i'll go over in a bit and 16 hours is a pretty small amount of time considering the complexity of the design and the number of features that means that if i was making this while working a regular 9 to 5 job i could get this mini game done within about a month and that's sort of what i did i'm always working on multiple projects and multiple videos at the same time so each is kind of its own side project so let's see how i managed to get all of this done in such a short amount of time but before we see that do you want to learn how to make games from a veteran in the games industry then check out this video's sponsor jason wyman who makes some great game development courses they are all extremely detailed and very well planned with expert life support whenever you need help as a special deal you can get the code monkey course bundle which includes not one but all three courses for the price of one it's a great guided path i will teach you how to make games from beginner to advanced learn all about c-sharp with the programmer course then master unity along with all of its tools and finally dive deep into the code architecture course where you will learn how to structure your games and write good clean code to help you make even better games jason is a veteran in the industry with many years of experience working on large teams and very complex tripoli projects through the course you also gain access to an exclusive discord server where you can chat and share ideas with fellow students also as a bonus if you pick up the course bundle through the link you get steam keys for all of my games as a nice free bonus along with a mug hoodie and discount on future courses so if you want to learn how to make games check out the link in the description now as i try to mention as much as possible on this channel if you want to be a successful indie game developer you should always write clean code so you can easily reuse it in the future so for my starting project instead of starting from a completely empty new project i started directly from the grid building system that i made recently in that video i showcase how to make it using city builder as an example but i also mentioned how you can use it to place down any object it doesn't have to be just a city i can use it to place down resource nodes and conveyor belts so it's perfect just for this use case in about 60 minutes i took the code from that video and just made some new object types making some resource nodes some buildings and some belts and everything was working flawlessly so this really shows you the power of writing clean reusable code i first made the underlying grid class over two years ago and then i made the building system on top of it just a few weeks ago and now i'm using it to very quickly get a game up and running so with that i had some objects placed down and now it was time to think of how they should work by the way if you find the video helpful please hit the like button it's a tiny thing but really does help thanks actually even before i start the project i first made a very rough sketch of the game design that i was going for personally i like to think on paper in terms of design and then when i've thought enough then i get to writing code so i wanted the simplest form of a factory automation game as possible i define just two base resource types then processed versions of those resources and a final item that gets crafted from those resources just to find the buildings needed to make all of that work along with some conveyor belts and that's pretty much it that was my rough base design you should always have a basic idea of what you're trying to accomplish otherwise you'll just be spinning your wheels without knowing where you're trying to reach so i got to work on implementing that design first logic i handled was the mining machine just something that generates resources over time thanks to how i structured my code it was super easy to add just make a script that inherits from my generic placed object class and attach it to the prefab then just write a very simple timer code and that's pretty much it the mining machine is generating resources next up i started working on the grabber it's supposed to grab an item from one location and place it in another so all i needed to know was to grab the grid position from the graph position and the grid position from the drop position with those two i can then lock in the grid and see if there are any buildings placed on those two positions it's very simple and just with this i already had an interesting interaction between these two buildings now after grabbing the item i want to drop it so it was time to make some conveyor belts again i made the building and the script attached to it the goal was to take whatever item is on top and move it to the next position and for that to work they all need to know what is the next position which is defined by the rotation of the object and by the way sometimes i post gifts with what i'm working on in the youtube community or on twitter so if you want to see what i'm working on as i'm doing it then make sure you're following me there now there's one really interesting thing that requires some trickery to make it work that you might never have thought about if you've never made a game in this genre so a simple question how do you move objects in the conveyor belts it seems simple doesn't it you start on this belt and then if it has an item you check if there's space on the next belt and you move the atom then you check the next belt again see if this one has an item and if the space is clear and if so move the atom simple enough but now comes the tricky part let's say you first test this belt instead of the other one this one will test for the next belt if it is empty and right now it's not empty so it does not move same thing for the next one this one is full so it does not move in the end the only one that moves is the very first one and all the other items stay stuck so if you're not careful you end up with belts that only move if there's one empty spot in between the atoms one solution to that is to start moving the atoms from the last position in the bound and move backwards that means we need to keep track of each belt path so where it starts and where it ends that was one of the tasks that took the longest time to implement about two hours trying to wrap my head around how i could set all this up i need to create a belt system to handle all the belts of their connections and sort them all correctly it was very tricky to get it all working in fact i had a handful of infinite loops that just crashed unity one issue was with loops the way the code identifies the first belt is by essentially going backwards to the path well if the path loops then by doing that on logic it will continue going on and on and on so yeah that was a very tricky system with a bunch of issues and some weird edge cases in the end i got a really nice system i can place bounce anywhere and the system automatically detects and groups and merges various belts into a handful of paths it was very trick to do but the end result looks great i even made a handy debug visual so i could see exactly where each belt starts and ends for the timing of the bounce i once again reused a very useful class that i covered in a video two years ago the time takes system this is something that i've used in pretty much all of my steam games for example in blueprint tycoon all the logic on the blueprints runs on the tick instead of on every update that's an excellent way for keeping everything in sync and also saving up on performance so here i defined the tick as every 200 milliseconds and made the bounce work on that every tick the belt system listens to it and takes an action on every single belt with the bounce working the next task was finishing up work on the grabbers they need to grab items from one position and drop in another while making this game i was always thinking about keeping a good clean code architecture so instead of interacting directly with a specific item type instead i have two interfaces one for holding world items another one for storing just virtual items wrong items means they already exist in the world whereas these stored items are simply a number i covered interface in detail in another video they are extremely useful essentially i can make the code work with the interfaces and that means it automatically works with anything that implements those interfaces so the grabber works directly with those interface so it can work with all kinds of buildings it can grab or drop an item from anything that implements either the storage or the worm item slot so it's some simple code but it's extremely versatile the next task was implementing storage and that was again extremely simple just implement the interface and that's it it instantly worked perfectly in conjunction with the grabbers with that i had a working base system still needing lots of rules but the basics are there buildings can be placed the mining machine generates resources the grabber takes those resources and drops them on a belt the belt moves around and the final grabber takes it from the belt and drops in storage next it was time to make some proper resource item types for this once again i reused scriptable objects i did pretty much the exact same thing that i did in my crafting system video i defined a scriptable object for each item type another one for each recipe the recipes just have certain input and output items along with the type amount and the effort needed to craft again using scriptable objects is an excellent way to keep things nicely organized and with this i have all my discrete objects in my project files for each item type with the item types defined then it was time to finally use them this was also the point when i made the live stream i needed to keep working on the game so i figured if i'm going to work on it i might as well make it a live stream just in case people want to watch me work that was quite a bit of fun answering questions from chat and having all those people alongside me i'll probably do more live streams whenever i do another project like this one it wasn't really pre-planned i only set it up 30 minutes before so make sure you hit the bell icon so you know whenever i do another one so the next goal was to make the smelter to finally have some proper crafting i wanted to turn iron ore into iron ingots handling the crafting was relatively simple again i defined a scriptable object for the item recipes it has some inputs and some outputs then the crafting itself is just a simple flow timer and after some time the base items get consumed and the final item is created so it's some pretty simple logic up until this point the items were still manual so i was manually saying that the grabber was instantiating a specific type of items and also up until this point the mining machine had some resource generation but it wasn't based on anything so the next task was to add some rules to that i needed to identify what resources were in range and how many but before i could add that logic i first needed to place down some resource nodes on the map so i made a simple script that let me place them in the editor and they get spawned as soon as the map starts with that i had some starting iron and gold resource nodes then on the mining machine to identify those resources on my builder defender game that i made for my complete course in there for the resource logic i made it using a physics cast but since this game is grid based i defined a great shape and set i went for the simplest thing possible just a basic square shape if it is within a certain number of cells on the x and y then it is within range so just ask the grid if there's a resource node in that position if so grab the type with that i now had two resource node types and by placing the mining machine near each of them i could mine different resources next up it was getting tricky to identify the atom types without proper icons so for that thankfully i already had some items drawn from many years ago about five years ago i made blueprint tycoon and i drew a bunch of items for that and thankfully i had exactly what i needed i had some gold ore gold ingots iron ore iron ingots and also a computer so that's another benefit when you work on mini-games over many years you end up building a library of not just code but also assets so i quickly added those to the game and everything started to take shape at this point i had resource nodes i could place mining machines and mine those resources then some grabbers to grab them and drop them in the belts and then further ahead added smelters to make ingots and finally just for testing i could add another smelter to turn those ingots into computers so really awesome stuff this was when the live stream ended it was actually quite productive thank you if you join me on the livestream if you want to be notified whenever i go live next make sure you hit the bell icon so the game was looking good but still tons more to do next up it was making some sort of ui up until this point there was really no proper ui at all i started making the ui for the smelter to be able to click on it to choose a recipe it's pretty simple to do just make some templates go through the code and set them up then with the button i make it change the recipe scriptable object on the smelter also it was super easy to add the window track ability since i already did that in a previous video just add the script and everything works and with that the smelter ui was functional then at this point the game was close to being done in terms of functionality so it was time to get some proper working visuals i went through all of the acid packs that i bought over the years and grabbed a bunch of acids i made some blue rocks for the iron some yellow for the gold then i drew some simple moving arrows for the conveyor belts made a simple grabber added a bunch of props and buildings to make the storage mining machine and smelter so it's all composed of various props they honestly really don't make much sense i mean why does the mining machine have a truck or why does the assembler have a huge color so it looks weird but anyways it does work the game now had some proper visuals then making some proper ui buttons i just took some screenshots from the prefabs and made some icons making good visuals or even just choosing good visuals is definitely not my strong point but i'm quite happy with this look i'm especially happy with the ui buttons i think they look really good having the icon pop out from the background next up it was adding some particle effects then making the map a bit bigger and more interesting playing around the terrain adding some grass some rocks then a bunch of sound effects and then it was just polishing a bit of everything and here's the final result alright so here i am starting off on game so just got a terrain with a bunch of bushes a bunch of rocks and things and as you can see all the various resource nodes so first we want to gather some resources so over here i've got my icons for all the various building types so i've got my mining machine and as soon as i click it enables the tile map to show the buildable and non-buildable areas so right now i can simply go and place a mining machine near my iron ore and now it's going to be mining iron so if i click on it i can see that it is already mining so next up i want to grab the atoms from the mining machine so i can press r to just rotate and now the grabber will be grabbing items from this grid position onto this grid position so if i now just place a belt on top of it yep there you go now it starts grabbing the items that the mining machine is mining alright so that's the first step next up i've got these basic items this is just iron ore and the next thing i want to do is convert it into ingots so over here the other building type is the smelter so i can go i can rotate it and place it and in order to feed the atoms onto this mounter i need the graver so just rotate it and place it then i can click on the smelter itself to open up the nice ui where i can select what recipe i want to do so in this case i want to make some iron ingots so the grabber is going to input all the iron ore and over there we've got the crafting and after crafting is done yep got some outputs so here i've got a lot of the basics already working so i've got some resource nodes i've got a mining machine i've got a grabber that takes items from one place and puts them in another i've got the conveyor belt which constantly moves the atoms around and another one which takes an item and process it into another item type okay so over here i've got some iron ingots and then let's say i want to grab them and i want to dump them in storage so this is another building type so just storage place it in there and i bring those in there and just replace the last position with a grabber so i can also demolish buildings so just go place it in there and there you go now my storage is indeed receiving iron ingots alright so this is the most basic thing now let's do the same thing over here to gather some gold ore all right so there it is now i've got another production line so this one is mining some gold ore then moves it around puts it on the smelter and the smelter converts condor into gold ingots okay now for another building type over here we have the assembler so this is what makes a more complex building assembly so let's place it over here there you go looks really nice and again i can click on it and see what can i build so i can build some computers or some microchips so let's make some microchips first and this one actually requires gold ingots and then copper ingots so copper is another resource i placed all the way over here all right i've got copper being produced and as soon as it is then it gets placed over here in storage so now comes another really interesting feature which is that the gravers can actually grab just a specific time so over here i've got my storage i want to grab just what i need so i just need some gold and copper so let's grab those so i'm going to place these drivers these two and now i can click on the grabber and i can set a certain filter so this one will grab anything this one won't grab nothing or a specific item type so in this case let's grab some copper ingots and on the next one we're going to grab just the gold ingots and as i put them if there you go now it does start grabbing so now just feed them into the assembler and it will now start assembling some microchips so now with microchips let's just make some laptops all right there you go so i've got some microchips coming out of here and they go in there and we're starting to make some laptops and then finally just dump them into this storage just like this there's already a really nice base here so i can continue expanding upon this alright so i just built something really nice using all these mechanics and as you can see yep this definitely looks like a factory automation mini so all the resources going in all of them being crafted and my final output in here so everything is looking really nice all right so this was really interesting to make you can play it for yourself on the steam app you can also download the projects files to see how everything works for yourself and most of what i built here i covered in separate tutorials the core of it is the grid building system which i covered in detail in another video and the base for the grid system which was also made in several videos that you can find on the playlist so check the links in the description for references to all of those videos also hit the bell icon if you want to be notified the next time i go live working on my next project and don't forget to check out jason wyman's courses with the link in the description get the code monkey bundle and enjoy all of my games as a free bonus if you found this video helpful please hit the like button this video is made possible thanks to these awesome supporters go to patreon.com unitycodemonkey to get some perks and help keep the videos free for everyone thanks for watching and i'll see you next time you
Info
Channel: Code Monkey
Views: 66,947
Rating: undefined out of 5
Keywords: unity factory game, unity automation game, code monkey, unity grid building system, unity factorio-like, devlog unity, city builder devlog, devlog, devlog game, automation game, factorio, satisfactory, grid system, building system, unity grid map, factory games, unity factorio, factory, automation, unity 3d, house building system, unity, city building games, city builder, game design, game development, game dev, unity 3d tutorial, programming, coding, c#, code, software development
Id: 88cIVR4KI_Q
Channel Id: undefined
Length: 18min 16sec (1096 seconds)
Published: Sat Feb 27 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.