Make an Action RPG in Godot 3.2 (P4 | scenes + ysort node)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good morning afternoon or evening wherever and whenever you are my name is Benjamin and welcome to the Godot action RPG series this will be video 4 or part 4 in this series and in this video we're going to be learning about creating scenes for our different objects inside of our main scene here inside of our world scene and potentially a few other things we'll see how things go so in the last video we learned about collision shapes like this and setting up some collisions for our character so here's here's the problem that comes up ok so let's say you have this level right here and you've got your character in this level and you create another level so let's create a new scene we'll just click the little plus button up here and do a new 2d scene and we'll call this level 2 this is just an example right and so we create this other level and we're like ok well we want to put well we won't save it don't need to save it we're like well we want to put our player character in this level and well let's see we have to create a kinematic body 2d right so kinematic body 2d right here I'm gonna name it player we've got to attach a sprite to it right ok so a sprite right and a Collider and you can see where I'm going with this right this is a huge pain we don't want to have to do that so Godot has a system built in place for creating scenes from exist existing kind of objects right here or node structures so we can see that our world scene is made up of multiple different nodes inside of it right and if you go down a layer our player scene is also made up of multiple different sprites inside of it right here and so we want to be able to create a scene of our player that we can then re re instance in multiple different levels and this is really easy to do you can just right click on the player and we can do save branch as seen here we go we'll do save branch as scene and we can save this wherever we want to we're gonna save this inside of our player folder and it will be called player TSE n save and look at that now our player is a single note or technically a scene in this case inside of our world scene and if we want to edit the sprite on our player or the collision box there's now this little icon next to the player that looks like a little scene or one of those I don't even know what those things are called right from plays or movies the little thing that claps in front of the camera it looks like one of those and so we can click on that and that will open up our player scene and you can see this scene it opens up a new tab up here just like our world tab and we can edit all of the properties inside of this player scene and if we go back to our other level right here we can actually go into our file system and find our player and our player scene right here player dot tsum we can drag and drop this inside of our level now why is it doing that why does it show the player over there and then drop them right here what's going on with that well that is actually a really good question and so what we'll do to fix that as well actually open up our player scene again and you can see when we created our player as a scene it actually created the player in the same position relative to the origin that it was inside of our world and so what we actually want to do is come in to our player kinematic body here come in to the Claire transform and you can see our position right here and we want to reset this to 0 0 0 so that sticks our player right there in the center we can then save our scene control s saved our player scene right here and we can delete all these I'm going to use shift to select them all delete them all and now when we drag and drop our player into the scene it should do it properly of course it's snapping a little bit because we have snap on but other than that it's lining up perfectly so we can have multiple players and we can select these and delete them like that and we'll get rid of that second level because that was just for the sake of example and we come back into our world you can see it moved the player up into the top right hand corner and this is because when you make a change to the base scene here it will update all of the children scenes to be that way however if we move this this instant scene that we've made back out here it won't actually change the base scene the base scene will stay the same so now if we run the game nothing is actually changed by our game function only works exactly how it did before however it is our project is now organized better than it was before and that's easier for us to manage as developers so we're going to create a scene for our bush now this bush is just a sprite so we don't actually need it we're just gonna delete it actually and we'll come up here I'll save our world scene we'll come up here and we'll create we'll add the little plus button to create a new scene we'll make this a static body 2d because we want our bushes to be able to be collided with so we'll choose other node here static body 2d and we'll call this bush and we can come over here to our origin because that's where it's going to be created we'll add a sprite node to that we'll come find we can search on our filesystem here for Bush and we'll drag the bush PNG into our texture here and our texture property here on our sprite so now we're going to add a collision shape to this bush and we'll just do a collision shape 2d and once again I'm going to do a capsule shape and we're going to rotate this capsule by negative 90 and we'll shrink it down to something like that I'll move this down to about here there we go and that's a pretty good collision that way our character should be able to come behind the bush up here a little bit so the bush has you know if you imagine the perspective this is about where the Bush's shadow would cast on the ground and that's the kind of space that it would take up in the world so if you want the exact properties you can use the position here the rotation and I'll click on the capsule shape here and you can set the radius and height to be exactly if you want to set up exactly like mine now we save this scene our Bush scene and we'll save it under world save it here and if we come back into our world we can delete this random static body that we made don't need that just delete it and we'll instance our Bush in here we can just drag some bushes in here now this is actually a good time to talk about why I like to use the world as a base or though the node 2d as a base for my world there's some different reasons for why you'd want to do that if you use because you can technically use just a base node for your world here so I'm going to do that will say world two like this so let's talk about the differences between these two real quick because this is helpful to know why would you want to use one over the other one benefit of using a node 2d or draw back you can see it as both is that you can technically move the world node 2d around and it moves everything attached to it so you could technically I there might be a reason you would want to do that in a game you know like have everything shift for some reason and so that's possible you can't do that with a node because it doesn't actually have a transform as you can see over in the properties another thing is if we drag a Bush into our world it places it right there right however if we're in world 2 here and we try and drag a bush in the scene it always sticks it right at the center and then we have to move it well that one worked because it was it was a child of our bush if we if we make it a child of the world you can see every time we drag-and-drop and they get stuck up here so that's a drawback as well and so in my opinion using a no duty the benefits outweigh any potential issues you could actually drag your world around but then you can just set it back to zero zero and you're fine or you can even just lock it so that you never accidentally click on it right so yeah that's kind of the differences between using and node 2d and a base node and I've kind of discovered that along the way as I've been using Godot so let's don't save this will close out of our Bush scene we'll close out of our player scene and we'll save here and I want to do another thing in this video so we've learned about how to make a scene right and you can actually instance scenes inside of other scenes so if we come to our player here click on our player scene we can actually instance our bush inside of our player scene all right we wouldn't want to do that but if we do that and save then we're gonna have a bush following our player around and it will be you know a child of the player scene it will try and move with it and that's kind of weird but you can do that and why would that be useful well let's say you have a city scene right and in that city you have different houses and in each house you have chairs and tables and people write all of those can be scenes instanced inside of other scenes and it's it's a little bit hard to grasp it first for beginners this is one of the hardest things that I've noticed for beginners to understand about Godot but that system is extremely powerful because you're organizing your game by these different scenes and you can make each scene work on its own so it doesn't have to be so it's not connected to any other scene that it can be independent of anything else and that makes your project much easier to manage because because if you need to edit the player scene you just click on the player and you manage everything inside of the player you don't have to worry about a lot of code outside of the player right it's all kind of isolated each organized into its own little compartment and so this is a very very powerful system and once you get used to it it will change the way that you make games and so that scenes for you now the last thing I want to talk about in this video because I was I considered doing this in two videos but let's just student one because this is a shorter video let's talk about why sort so if we play right here and we move our character around in this room you can see the depth doesn't work when we're down here the player is the players behind these bushes and probably but like the player is always behind the bushes so the collisions are working properly how we want them to but the depth ordering isn't so there's a node that you can use for that and for now we'll just set our world node to be this we may end up changing this later but if we right-click on our world node you can do change type and we can set the type here to Y sort now a y sort node what it does is any any node that is a child of it it will sort the depth of those nodes by their Y position so on the vertical axis and so that is really powerful because then we can easily sort we can come behind here and in front here right you can see it's automatically doing all that sorting for us now there is a problem there's one more problem here and you will see if I can I can't I can't actually trigger but the problem is that it sorts them based on the center of the scene so if we open up our bush on our player so where's the center of the player scene well it's right here on the players neck it's actually sorting the player right here at this point but that's not where we want the player to be sorted a better spot to be sorted would actually be right down here at the players feet so in order to do that we're going to select our sprite and our collision shape by holding shift to select them both and move them whoops and move them both up that just move the player oh it's because we have this on still remember earlier when we made it so the children weren't selectable well let's check that we don't need to worry about that anymore so clicking on it undoes that now we can select the sprite in the cluttered shape and move them both up - let's turn off snap so we can get a single pixels and move them up to about I don't know maybe we'll do here that seems pretty good and so what position is that the sprite transform is 0 negative 9 the collision shape transform here's the capsule size just set that to 4 4 & 4 and the transform is white as a weirdest print transform we're going to set the X to 0 and the Y to 0 as well 0 0 there we go so you can have it set up exactly like this and now it will sort it based on this point so if we come if we have a bush that is sorted based on its own point so we're going to do this with our Bush to will select the sprite in the closure shape move them both up until it's here and once again here the transforms if you want to copy those exactly negative 4 & 0 for the collision shape so that means our Bush will be sorted at this point it's important because if you're sorting isn't working properly if it looks like if it technically is sorting but then it does weird weird stuff where like it sorts properly unless you get past a certain distance then your player then you need to make sure that you've set these up like this and I actually want to show you it did I'm gonna do an extreme reverse example so we'll sort the player by the head clear up there right so this will technically work still but you can see you can see how it sorts properly until we get to here that's because it's using the sorting position of the bush and the sorting position of the player right you can see imagine there's a little dot here for the bush in fact let me show this it's always better to show it so we'll take a little screenshot here now come into paint.net and paste this okay imagine you've got your point here for the bush right here and your point here at the head of the player right this is where it's sorting them from and so that's why it works properly at first that's why it works properly right here because the origin of the player is lower than the origin of the bush so it's drawing the player on top but once the players origin right here passes the Bush's it sorts the player behind the bush that is why it's important to make sure that you have your origin set up properly this is where we want to sort the player at right kind of like at the center if you imagine a pole going down through the player right here to the ground right in the center that's about where we want it this sort but I think the Y sort node is very cool very powerful really easy to set up and then we automatically have Y sorting we can come into our debugger turn off visible collision shapes run the game again and this just looks really nice looks really good so thank you all so much for watching this video I hope you enjoyed it and learn something from it and if you did be sure to give it a like let me know in the comments if you have any questions this video the sponsor for this video is actually my Kickstarter backers who were able to fund my one bit Godot course and this series being part of that course I will a belong YouTube for free and I really appreciate them in their support if you're interested in that course check it out and I will talk to you all later
Info
Channel: Heartbeast
Views: 227,913
Rating: undefined out of 5
Keywords: Godot Engine, Godot 3.2, Godot 3, Tutorial, Series, Action RPG, RPG, Pixel Art Game, Indie Game, Game Development, Learn gamedev, Gamedev
Id: UfKMgHbaGow
Channel Id: undefined
Length: 17min 28sec (1048 seconds)
Published: Thu Mar 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.