How to switch scene using door (portal) in Godot 3? - BACK AND FORTH (Part 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
i am a king of this level i'm going to the level 2 and i'm going to the level 1 and i'm going to level 3 and i'm going to level 1 and i'm still going going club at 4 and i am on a good position every time this is tutorial about it for the start setup we can use the project from the last video how to switch scenes using the door and the code is on the description just click it download it and let's go after open the project you should have situation like this when you run it you have the first level the player can go to the second level but he can't go back so we need to fix it to do it you need to open the door script and change this line in the previous project we were using the packet scenes which is okay when we have the situation when the level 1 have a level 2 as a packet scene everything is ok but when you need to go back to previous level for example the level 2 have a level 1 as a packet scene we are creating an endless loop because the level 1 have a level 2 as a packet scene and this level two have eleven one as a packet scene and this one level one have a lap in the rubble blue and so on the solution is use the strings so let's change this line for the string parameter read from file with the extension which are ending with the scene or the tree scene the second thing we need to change on the script is this parameter because like you can read on the documentation the change string the change scene are getting the string parameter but the changes in two are taking the packets in now we need to update the level one door and the second level to go back to first level and everything should working let's go tick tick tick tick back we are in the level second and we are back in the first level this method is working also when you have more levels so let's create them this solution is working fine for the many levels like you can see when i'm going to level three i'm on the level three when i'm going to level four surprise i'm on the level four the problem with this solution is that the player is always on the one position and this is the start position so everything is working because we don't have the analogies to change this so let's change this to achieve this we need to use the global nodes if you don't know what the global nodes are please watch my tutorial how to do the music controller for kadu we have a great global variable that we can use to pass the arguments between the levels for example when we are going to level 1 and change this variable we can read it on the level 2 and level 3 no matter where that is a theory let's go to the practice let's go to the door script let's change this name the door name so the name of this door that is using the script and go to level one add script level one is a great name and here on the ready function let's print this very variable global name door name let's open the project and now it's null because on the start like you remember we have the null variable but when we will use the door which name which is the name dar2 and back to this level we will have the door because now we have the door 2 on this level but this door is named by dar and that's why we have the door inside this console so now we can use this for the connection bin between the door next step that we need to do is to connect the names so for example when we are on the level 2 this door should have the same name like this door and this door of course the same name like this there so we will have the information about which door to use so let me give a second we'll change this to dart 3 this door three and this for the door number four so now look at the console when we were back from level two we will have the name door too and here also will have the nice situation so now we have the information which door we need to use next step is very easy because we need to just do the position take the position from the door and attach it to the player let's go to the script level one and here will be the code code for finding the door at first let's check if the global door name isn't null that is enough next let's find the node by the name find out this standards function for function for it and now if the door node exists let's use let's change the player global position to door now the global position and that's should be enough let's test it we are on the level two and we are near the door of level one two yeah everything is working but the player is not on the middle of the door it is because of my door scene because the global position of door is here and in for the player is here so if i will move this to the middle and of course the global the collision box and yeah we'll change this stars everything should work let's go to this door go back tada and here ta-da and here so we need to need to change this labels but probably this is not important for this tutorial so thanks for watching have a nice day and so on
Info
Channel: Rafa Fiedo
Views: 6,348
Rating: undefined out of 5
Keywords: godot portal, godot, godot scene change, godot scene, godot scenes, godot change level, godot switch scenes, rafa fiedo, godot tutorial, godot change scene, gotod tutorial 2d, godot 2d, godot game tutorial, godot platformer, making a game in godot, How to get the nodes of other scenes?, godot pass variable to scene, godot go back and forth, godot set position 2d
Id: X8QNUCmmf5c
Channel Id: undefined
Length: 8min 29sec (509 seconds)
Published: Thu Nov 19 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.