How to make Enterable Houses - Godot Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

That's a great tutorial, thank you for recording and sharing this!

Using .resource_path on a PackedScene in get_tree().change_scene() is a really nice way of doing this I have not considered before!

FYI, you can easily add as many CollisionShapes to the same body as you want. They will be all treated as one. You don't need to create a separate StaticBody for each.

With pixelart tilesets like these, drawing level boundaries with a Tilemap tile that has collisions I find is the quickest and most comfortable way of setting up boundaries. Especially if you are already using Tilemaps for the environment anyway.

By using the Region property of the Sprite, you can also really easily use the spritesheet, saving you the time and effort of creating multiple texture files for the houses.

πŸ‘οΈŽ︎ 3 πŸ‘€οΈŽ︎ u/golddotasksquestions πŸ“…οΈŽ︎ Oct 02 2021 πŸ—«︎ replies

I’m actually curious about how to implement something like this, thanks!

Feedback. You seem to have a fuckton of tutorials (thanks fam). I would number them so new viewers (like me) know immediately that you have a lot of related content.

Also, do you share the source for debugging? I would have crashed and burned in the heartbeast action rpg tutorial until I did a quick diff and saw the vector bug I introduced.

Thanks again!

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/lostInStandardizatio πŸ“…οΈŽ︎ Oct 02 2021 πŸ—«︎ replies

Looks good, btw your Thumbnail has a typo in it β€œenering” not β€œentering”

πŸ‘οΈŽ︎ 2 πŸ‘€οΈŽ︎ u/ThrowingSpoon πŸ“…οΈŽ︎ Oct 03 2021 πŸ—«︎ replies
Captions
so today i'm going to go ahead and show you how to make houses that you can walk into and then leave and then also make sure that houses are different depending on which house you walk into now before you get started you're actually going to need a couple different things from some previous tutorials of mine all the links will be in the description and the icard so i'm starting out here with the simple top down movement i'm just going to take and restructure the folders a little bit i'm just going to make some files to split things up so i'm going to start with an art folder and i'm just going to go ahead and just move all the art i have into the art folder and then i'll do resources scenes and scripts that way it's just easier to see what is what in here i'm then going to take the player and make its own scene just call this player inside that scene i'm going to go ahead and add a button prompt this was added in a button prompt tutorial link in description i'm then going to go ahead and just change the collision shape because for the top down circle is better for the most part and i'm going to move that down there and i'm going to move that down there to his feet and just decrease the size just a bit now from that button prompt tutorial you probably have something that looks kind of like this code wise we're going to change that just a little bit so we're going to do verb instead of show prompt we're going to do house and this will be the house he's going to be entering and that's going to be set equal to null and then we're going to change this to set house this set house new house and instead of just checking if the new value is true or false we're going to do if new house is not equal to null we can do key prompt dot show and prompt dot play else key prompt dot hide and prompt dot stop the reason is because i ended up naming stuff different in this tutorial and also because house equal to null will be no house and then this is going to be an instance of the house so we could call stuff on the house and you shouldn't need this process from that we're going to handle the whether to show the prompt different or not you're then going to want to set up an environment with some houses that the player could walk into i showed this in a making environment tutorial link is also description i will drag and drop that over from the tutorial into this so i got the scene i built from that tutorial moved over so i'm just going to go ahead and add the player to it and i'm actually going to remove the houses because i want to do custom houses in this one where they each have their own script so i could give them each insights and stuff like that i'm also gonna put a y suit in here this i'm just gonna put it right between the houses and the other i'm gonna put the player in it i'm gonna put all the houses that i add into it so that the player could be in front of or behind the house depending on his position and now that everything is set up to get started i'm going to start by building the houses so i'm going to go ahead and just do a new scene this is just going to be house i'm then going to add a spray of a single house i was just going to use this and transition between them but the houses are all different sizes so changing the animation doesn't really work for that i went ahead and split up all the houses to be their own image and we'll start with the leftmost house that was house 2 and i'm going to set its position to about 0 negative 20. the reason i'm not setting it to 0 0 is with the y sort i want the origin to be a round here so that when the character goes more north when we're up than that they will be behind the house and move down from that they'll be in front of the house i'm then going to create a collision and i'm going to leave a little lip so you can walk right behind the house because this isn't completely top-down perspective the next thing i'm going to do is add an area 2d and this is going to be the doorway and basically when they walk into the doorway i'm going to make so that they could interact with it and enter into the house so i'm going to attach a script to the house and i'm gonna go ahead and just start adding that feature so the doorway i'm gonna do body entered and body exit when you enter the doorway we want the body to call body.house equals self so we're gonna reference this house so that the player we're gonna set the house and if the house isn't equal to null it's gonna set the button prompt and then when they exit the doorway we're gonna set it to no body.house but this is actually a minor issue if you have two doorways at the exact same spot when they leave one doorway it's going to leave both of them so we're going to do if body dot house equals body body dot house equals null that way if it's referencing a different body this house doesn't cancel them from entering a different house in most cases won't be a problem if it is equal to self we want to set it to no my bed enter the house into the area we have i think it was about right there and i'll give it a run and it crashes the reason is because body doesn't have a house and that is because this area is seeing the static body 2d so what we're going to do is make sure that the doorway can't collide with the house and that's going to be in the collision layer so i'm going to remove this and set this to there but actually layer 1 layer 2 becomes quite difficult so i'm going to go into project settings scroll all the way down to 2d physics and i'm going to do objects for now that'll be the house or anything you could collide with and i'm going to do player so i'm basically saying this could only interact with the player and it's not a part of any layer because we don't want anything to interact with it at the moment now if we look into the player the player is i'm going to go into the play scene player's collision is currently an object let's change that to player and player interacts with objects if this is a multiplayer game and you want plays to collide you would turn on player now if we run this and i have the wrong one selected so i'm going to go project project settings run click there and i'm going to select the note 2d now if we run this the player has his thing we didn't set up the ready to cancel that so i'm going to do font ready set house because having this doesn't default called the set house ready is already a thing let's just put that in there there you go just clean that up a bit and let's put the house into the y around this there we go that looks a bit better e appears and then e disappears now we're going to want to detect if they press the interact key which in this case is e so i'm going to do function unhandled input unhandled input allows us to make so they can't interact with stuff when they have a menu open essentially if event is input event key and event is action pressed interact and house is not equal to null we're going to call house dot enter so it'll be calling a function on the house so if there is a house to interact with and we press the interact key we're gonna enter the house so i'm gonna go in the house and add that function function enter and this will be what gets called i'm gonna go graduate settings input map interact add e and for now i'm just gonna print enter house so i'm gonna run this and if i press e well next to the house it's gonna say entry house okay so that did call that function cool cool next thing i'm gonna need to build a scene that is the inside of the house and for the inside of the house i found this interior home tile set i'm going to go ahead and download it link in description so i'm just going to drag that in make sure you turn off the filter for pixlr if you're not doing pixlr don't do that and then i'm going to go ahead and create another resource called inside so i have the outside of the house i'm going to do asus boot inside and this will be a title set and for this one i'm just going to do single tiles because everything will probably look the same inside the house and then i'm going to do a little black area for the background i'll call this inside one because we're gonna have multiple different insights and i'm gonna do inside i'm gonna add a tile map and i'm just gonna attach the inside and i'm gonna go ahead and just decrease the size let's do 16 16 because we're going to be starting with this one and i'm just going to call this guy void dot there dot there paint bucket and then i'm gonna attach a camera same zoom as the other one set it to current and then i'm gonna do another tile map and this will be the actual house so it's still too big i'm gonna do 32 by 32 and let's go ahead and have this one be the exit and i'm just going to draw a little nice house here and i'm going to go ahead and just drag in a player here and let's set up that transition so that changes to this house and the way i'm going to do this is i'm going to attach something to this that will be like export packed scene right inside scene and this is going to allow me to on the snow 2d just go ahead and click on that house and that'll be the inside scene i'm just going to go to inside one and just drag that right in there now it's going to have a instance of that scene and then on the enter we're going to change the scene to the name of that scene or the path of it so i'm going to get tree change scene inside scene dot resource path so that's going to get the path of it which is going to be the res scenes inside one and that's going to change the scene to that so i'm going to go ahead and try that went up to the house press e and it changed the scene and i can move around but there are no collisions or anything and i can't leave the scene so on the inside i'm going to attach a script for outside and the reason i would do a variable is because some of the insides might have different outsides if you're doing multiple different outside scenes for now it'll all just be the same scene and then i'm just going to do an area 2d at the door and we'll call this exit when the body enters i change the scene back to the outside however i don't want it to immediately change it back to the outside scene because the player is already standing in the exit so what i'm gonna do is i'm gonna do a variable called entry and i'll say if entered then i'll change the scene and then when they first exit the exit area and then i'm going to say they entered the house so i'm going to entered equals true so now i'm going to run this and then went in went back out and it didn't change this collision doesn't work with players yet so make sure you change that to only work with players looks like i named it the wrong scene i'm just going to rename this to outside name outside scenes i named everything wrong today and then you probably notice i immediately teleport back to the center when i leave the house so i go into the house go in a bit leave and it teleports me back to zoo zoo so we're gonna want to make so that it saves the place of the player before he enters the house that way he can walk out at the same part that or each house would keep track of a spot that spawns the player at when they leave the house either way you need track which house the player is in or where he entered from there's benefits either for this tutorial i'll show you how to keep track of the player so i'm going to set up a global script i'm just going to call this global project project settings i'm going to do autoload tell it autoload the script global add that in and then i'm going to do per player position and we're going to do a vector 2 and that should default to back to 2 0 so 0 0. now in the player when we tell him to enter the house we're just going to say global dot player position equals global position and then on the ready we're gonna say set position to player position global position equals global dot player position now we can run this and if we enter the house well it looks like we started over there because we didn't make it seem specific and we exit the house so we exited the house at the right spot but now it's not entering the house now we just make sure it's only doing this ready when they're outside not when they're inside and an easy way to do this would be just to move this to a script that is outside that way the player doesn't call it on themselves so i'll set up an outside script really quick and just move that instead of global position we're going to go ahead and do the why swoot slash player global position now if we try that we can walk into a house and then leave and leave at the same spot we walked into the house now i'm just going to show you how to set up a second house and it's basically the same but a little bit different i would probably just duplicate this house so we have house 2 and then you're going to go ahead and do editable children because instead of loading this house we're going to want to load it for your house and let's go ahead and build this house next so house two all these are gonna move around so i'm gonna lock them all for now that way i can move the main house there we go got it right over there i'm then gonna take this doorway put it right in the doorway and then just lock its position and then i'm gonna take the body of it unlock its position and just increase it to the size i want that will probably be good and i'm gonna need to add another body to cover up this section so i'm just gonna do another static body with a collision shape and i'm not going to worry about it being perfect because this is just a tutorial it looks like these are both referencing the same collision so what am i going to do is i'm actually going to change this collision back to there there and then i'll just replace both those because that fits there about there we go now this house is going to take you to the first inside so i'm going to go ahead and build a second inside for it so i'm just gonna duplicate the inside oh i'm just gonna take duplicate and i'm gonna call that inside yeah whoops inside two and on inside two we're gonna make it have kind of an l shape and i think it's a bit longer so i'm just going to go ahead and do the tile map draw kind of this l shape that way we have a different inside now if i go to the outside and i go to the second house i have the inside scene i'm just gonna drag inside two to that go ahead and run that test that and it looks like they both have different insights and we didn't really add glitches to the insides i'm assuming you guys could do that by yourselves just go ahead and do a static body and then i would do a collision polygon and then just draw the inside thank you for checking out this tutorial hopefully he was able to learn something and i'm looking forward to seeing you in the next one goodbye [Music] you
Info
Channel: Arith metic
Views: 911
Rating: undefined out of 5
Keywords:
Id: 9fbnuKkj5Fw
Channel Id: undefined
Length: 15min 21sec (921 seconds)
Published: Sat Oct 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.