Awesome House Building System! (Castle, Hut, Mansion, City, Village)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome i'm your code monkey and here is a really awesome house building system it's a great system for building any kind of structure so it has the ability to place down objects like walls doors floors stairs and so on it supports multiple levels so i can make some small huts or some really complex mansions and i can easily interact with everything with my normal 3d character then i also add the ability to place down some normal objects like trees barrels flowers and so on and just for fun i also made some quick npcs so this is a house building system but it's really not just limited to a single house in the final demo i have essentially a pretty nice village you can download the project files for yourself in order to inspect all the code it's a really awesome system and you can use this as a base to make a game where the player can build a house so something like a survival game or maybe a strategy game where you can build a castle or a tower defense game where you build a maze bunker so there's tons and tons of possible use cases for this system so let's see how i made it and how it all works but before 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 triploid 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 okay so let's see how i made the house building system as usual it is based on my super useful grid system if you are new to the channel go check out the phone playlist link in the description i've built a lot of this system over the course of many many videos the first one was two years ago so this system has been very useful for very long and in many scenarios my starting point was right from where i left off on the grid building system now in that one i made a system to place down phone buildings so kind of like a city builder game it's also the same system that i use in my factory sim game where i use it to place down conveyor belts grabbers and buildings so what i'm using here is really the same thing except instead of placing down buildings i'm going to be placing down objects so doing that was really simple thanks to how i previously set up the grid building system all i need to do is just create a new scriptable object to hold the object type so for example d4 then i just create an object for the prefab and another one for the visual so with just that in about 10 minutes i can already move the mouse around and click to play sound objects now initially the first tricky question was how do i handle walls now the simple approach is just to make the walls a normal object that occupies a position on the grin so this works fine but it does mean that the walls are quite thick so for some games this works great for example in prison architect it's a great game and their walls are indeed one unit thick but in my case i wanted some more realistic looking houses so i wanted the walls to be relatively thin now one approach that i could take to solve that would be to make the grid system super tiny so that one unit was very thin but if i did that approach then i could eventually encounter some serious performance issues with bigger levels so after some thinking i came up with a different approach i would place down the four objects the same as normal and then each floor has four edge slots so up down left and right and on those edge slots i can place down edge objects which occupy the whole edge so doing that lets me place down floors with a normal size grid and then it allows me to have some normal thin walls placed perfectly along the edges of the force and also just for fun in order to make the system look good as i was working on it i grabbed some proper visuals so these ones are from the polygon fantasy kingdom pack which i picked up during the spring sale it's got tons of modular building parts which made it absolutely perfect for working on this system there's a link in the description if you want to wear it for yourself it's a really awesome pack the next thing that i really wanted in this system was the ability to have multiple levels doing this was also quite simple thanks to how the grid system works each grid has an origin so that's a vector 3 for where the word starts so in order to make multiple levels work all i need to do is really just move the origin along the y axis so that's it very simple all the objects are placed exactly on their grid position so by just moving the grid origin it moves all the objects that are placed with it so all it takes is to know which system i'm interacting with and for that i really just made a button press and when i press it it sets the next root system as active with that i can have as many grid systems as i want to have as many levels as i need okay so with that working i just made a bunch more objects first of all added some stairs which work the same as the walls so it's an edge object so it's placed on top of a floor then i added a door object just made a simple hinge joint between the frame and door in order to make it move like a proper door and with that it was already enough objects to make a basic house with multiple levels and in order to play around with the house building system i also made a very simple character that i can move i just made some very basic movement code and grabbed some free animations from the store and for the visual again i used a character from the polygon fantasy kingdom pack so now i had a basic house and a character that i could control and by this point it was already a very cool system that would work perfectly in any sort of game where you want to add some building but then i continued working and expand upon it some more my next task was simply making some more object types so i made a different type of floor i made some walls with windows and some glass the logic is all the same they all use the exact same object types just the different visual prefabs so adding more variation to this system is super simple by the way if you find the video helpful please hit the like button it's a tiny thing but really does help thanks with all that working it was time to make a proper ui so up until this point i was selecting object types by pressing the number keys on my keyboard so i just made some very basic buttons took some screenshots to make the icons and some basic logic in order to click and select the object type for the references i used a singleton assets class just like you use in pretty much every project it's super easy to make and it lets me have direct access to all of those references anywhere in my code base with that i could now easily make some pretty complex houses and move around with my player character now the one important thing still missing was to make the player visible through walls it's really not very useful if you completely lose track of where the player is while inside a building so i need some way to see through those walls now there are many ways to achieve this effect i went with the simplest approach of just writing the character differently when behind an object this is actually quite simple to do brachy's made a really good tutorial on how to make it you just need to work with the render pipeline asset so first put the characters in their own layer then make a render object feature in order to render the characters with the behind material and only render them if the depth is greater so it only renders if the characters are included and a second render object feature but this one to render the characters with the normal material and it only renders if the depth is less so this one only renders the parts that are not included so by combining those two you have the normal characters when not occluded and a different material when included it's a really simple effect and works great in this scenario so with that i could now easily control the player inside any house then i made a quick and simple safe system just so i could start building some large houses and not have to remake them every time it's pretty easy to do just make a safe object that stores the object type and their grid position then on low just instantiate that same object in that same position it's all quite simple i covered it in more detail in another video so go check it out if you want to learn how to make a save system then just for fun i also made some basic npcs they just walk around through a bunch of waypoints and wait a bit it's very simple and it works to make the demo sim look just a bit more alive and to top it all off i made another type of object that is placed separate from the grin so these are the general objects which can be placed anywhere they're not linked to any great position i've had a bunch of rocks trees crates and so on again all of them from that same polygon fantasy asset pack and they also all work with the save system so i can place them all build a really nice village save and load and finally after all that here is the final result so i start off and over here i've got my basic layer character so i can simply move it around yep there you go looks pretty good and also i've got some basic camera control so i can move around rotate and so on so let's first place down some force so i just go into the ui to select the object type that i want so let's begin by placing some force just like this one and over here is the real nice building ghost if you want to know how this works i covered it in more detail in the grid building system so i just have i just unlocked where do i want and just start placing down some floors as i click on them you can see that they snap perfectly onto the grid so there you go here's a nice house now next up let's place down some walls so i select the wall object let's place these types of walls and now as i move the mouse over you can see that it snaps into the various edge positions so if i put near this edge it connects into that one that one down and down alright so i just placed them alongside all the wall edges now let's add a simple door just so i can go inside and okay here is a very simple hut now let's add a second floor so for that we need some stairs and let's light the stairs object and just connect it over there okay now i need to place down the floors on the second floor so i just press the f key and up here i can see which grid level i currently have selected i could also add a simple timer but i thought it looked a bit better being just like this so like this i'm playing around on the first level and i press the f key and there you go now i'm on the second level so you can see yep it's all up there so as i swap them around you can see i've got a total of four levels all right so in here and i can just place them and now up here and let's place down some railings so just like this looks pretty good alright so that's it here's my very basic house and now i can move my player character go inside go up the stairs and up here i am over here and yep there's my only working house now to make it a bit more pretty i can place down the general loose objects so i can click on this one to toggle between the various types that i added so let's place some crates maybe down here then some books maybe all the way in there then some flowers let's put some flowers right in there for a rug let's put a rug rotated a bit put it in there and finally some nice trees so let's put them right around here all right so look at that here is my nice home and i can control my character go up go down go outside go behind the trees and so on and yep it looks pretty great so now i can hit the save button and if there you go it's saved now i can quit and now i can hit play again okay so here i am back on an empty scene and i press the unload button and there you go everything loads exactly the same as previously so all the objects exactly where they should be i can play around interact with them and yep everything works perfect all right awesome now here is my final demo scene so i build all of this exactly like you just saw so i've got all the various floors the walls the stairs the objects outside and so on over here got some nice glass a nice garden and over here i got a really tall building so i've got my character and i can just walk around and go inside any of these buildings and just interact with them and just for fun i also made these nice npcs so again they are characters from that same asset pack so here is a real nice king a real nice monk and so on and yep they just walk around through various positions just to make this look like a pretty nice living breathing village so as you can see this system is relatively simple but by adding some more complexity onto the various object types you can make them look really good in order to make some really nice cities alright so that's the phone demo you can download the project files and inspect them for yourself to see how all the code works now in a future video i would like to take this system and convert it into a first person or third person view so essentially i would like to take this and make a billing system kind of like valheim so you have the camera behind the player and you can point and look to a position in order to build something so that's my next goal to expand upon the system so make sure you hit the bell icon so you don't miss that future video 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 alright hope that's useful check out these videos to learn some more thanks to these awesome patreon supporters for making these videos possible thank you for watching and i'll see you next time you
Info
Channel: Code Monkey
Views: 35,332
Rating: undefined out of 5
Keywords: unity building placement, unity build system, unity house tutorial, unity build room, unity house building, unity building game, unity building tutorial, unity construction, code monkey, city builder, unity house, unity strategy, unity city, unity survival, unity tutorial, unity game tutorial, unity tutorial for beginners, unity 3d, unity, game design, game development, game dev, game development unity, unity 3d tutorial, programming, unity tutorials, how to make a game
Id: Cdcn6uK9gPo
Channel Id: undefined
Length: 12min 54sec (774 seconds)
Published: Sat Apr 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.