How To Switch Levels - Godot 4 Simple Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to take a look at how we can make different levels and scenes in gdau and make it so that we can have something like where our player can walk into different levels and walk back into our previous levels okay so the first thing I'm going to do is create two folders one is going to hold all my scenes and the other folder is going to hold all my scripts and then I'm going to create my first level which I'm going to rename and it's going to be called level white and I'm going to arrange these levels in terms of colors so for this let me add a color wct and I'm just going to stretch this out just so it fills the whole thing and let me hit save okay so I want to go into scenes and Save My Level white and I'm also going to create my player so let me open a new tab and control a and this one is going to be a character body 2D and let me add a Sprite 2D okay a Sprite 2D and in instead of this I'm going to drag the icon let me move it up a tiny bit and let me also add a collision shape so our player can collide with the world and for the shape I'm going to use a rectangle and let me just make sure it fits okay so it's not too important for this so just the P will be enough okay I'm going to I'm going to rename this to player and let me hit save okay so let me hit save and then I'm also going to add a script to this player so it can move around so this one is going to be saved inside of scripts right and for the movement let me go into project project settings and input map and let me add movements for up down left and right for each of these let's add the key we want so for up I'm going to use up for down I'm going to use down for left I'm going to use left and for right I'm going to use right okay so let's hit close and let me Define a speed for my player so this is going to be 500 and inside of the phys process function I'm going to use the move and slide function and let me set the velocity which is going to be equal to the direction so let me actually uh let me Define the direction here bar Direction and this is going to be input do get vector and we're going to be using left forx right right bit of a mess but anyway this this is what it finally looks like after bit messing around and the velocity is going to be the direction times the speed and let me hit save on that let me go back to my level white go on 2D and let me drag the player inside of here so control shift a and let me get the player and let me drag the player somewhere around here and let me hit save and then I can press play over here select current and now I can move around with my player okay so let me create uh two more scenes so this one is going to be my second level going to call this level blue okay and let me add a color wct to this as well color wct okay I'm going to go over to color and I'm going to type in blue and let me drag this out so it can fit the entire screen okay and I'm going to hit save and this is also going to be inside of my scenes and let me create one more level and this is going to be my level red okay and I'm also going to add a color wct and this one is going to be red let me drag this out so it fits the entire screen and let me hit safe okay so this my red red level this is going to be my red level so let me go back to the first let me go back to the first um level and I'm going to add away so we can go into to the blue level actually before we that let's go to the blue and before we do that let's go to the blue level and let's add the player in here too so I'm going to grab our player and put him here okay and hit save and I'm going to to go to our red level let me get the player and I'm also going to put him here too and hit save okay so let me go back to our white level and right at the edge I'm going to have a door right which when we hit it's going to take us into the next level okay so to create the door we need an we need an area 2D okay and this area is going to be let's say door to Blue the door to level blue okay and let me add a color W to this a color wck let me click on the color and this can be blue and I'm going to drag this and I'm going to drag this all the way over here okay let me make it slightly larger and I also need to add a collision shape to this okay so a collision shape 2D and this Collision shape is going to be a rectangle and let me drag this let me drag this all the way over here and make sure it fits here okay so make sure it fits here so we can actually detect when our player has hit the door okay now what I need to do is I need to create a script for this level so I'm going to hit create and inside of scenes inside of scripts I mean we're going to have a script for our white level and we can get rid of this okay let me hit save and over on this over on this area 2D for this blue door I'm going to go over to node and I'm going to use the signal body entered so we can tell whenever our player has entered this blue door and I'm going to hit connect and now we have this we have this function that's going to run every time our player enters the blue door and whenever it ENT is the blue door what I'm going to do is I'm going to get threee and then I'm going to change scene to file and I want to change it to the level blue and let me hit save go back here to 2D and let me run this now so now I can move around and when I enter this blue door it takes us to the blue level okay now we can do a similar process so we're going to go over to our blue level and now we're going to do the same thing I'm going to make doors for the white level here and the red level here okay so what I'm going to do is I'm going to add an area 2D okay this is what we're going to use to detect this going to be the door and this is going to be a door to level red okay I'm going to add a color wct let me go to inspector color and let me type in red okay let me drag this all the way over here right to the boundary it might be a bit hard to see make it a bit larger let me put it right on the edge and this also needs a collision shape okay it needs a collision shape 2D and the shape of this we're going to use a rectangle okay let me drag this all the way over here and let me make sure that this fits let me make sure that this fits our door and the same thing we're going to create a script for our blue level okay so inside of script I don't need this code here but what I do need is I need to go to the red level door go into node and I need to first let me save the script make it's saved and then let me go into body entered right and I'm going to connect it and same thing over here what I'm going going to do is I'm going to get the tree and then I'm going to change the scene to the red level here okay so let me hit save go back to 2D and if I hit play okay so I can enter this door and I can find the red door here when I go there I can go to the red scene so as a challenge you can try this yourself to basically repeat this process for the red level so we can have a door that goes back to the blue level and maybe we can have an extra door that takes us back to the white level thanks for watching
Info
Channel: RKCoder
Views: 441
Rating: undefined out of 5
Keywords:
Id: uy4GGG4nQUM
Channel Id: undefined
Length: 9min 35sec (575 seconds)
Published: Thu May 23 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.