Godot Networked Multiplayer Shooter Tutorial #1 - Initial Multiplayer Connection

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Is it peer to peer?

👍︎︎ 3 👤︎︎ u/tortfine 📅︎︎ Mar 16 2021 🗫︎ replies

Very good tutorial, I just started learning Godot with multiplayer on mind and this is very instructive

👍︎︎ 1 👤︎︎ u/lorenzohowar 📅︎︎ Mar 17 2021 🗫︎ replies
Captions
all right this tutorial series will feature a local area networked multiplayer top down shooter automatic server browser so we'll have a server browser on the game and it will automatically find devices that are hosted on that ip address and it will feature lag compensation which a lot of tutorials i've looked into have not shown so that's why i'll be showing all these extra things and i hope you guys will enjoy all right you're going to hit project you're going to go project settings we're going to scroll down we're going to hit window all right and we're going to set our size to 1920 by 1080 and set the test height to 1280 by 720 then we're going to scroll down into our stretch mode to 2d and our aspect to keep let's make a new script we're going to call this network all right i'm going to just find some variables we're going to need a default port in our max clients then we're going to need the server and client these will be e-nets we're just seeing them as global variables for now so then we can access them later then we're just going to set an ip address and that will just be a string then in the ready function we're going to be checking if our os name is windows then we'll set our ip address equal to the ip.local addresses 3 index 3 and this will also be working on android so android uses index 0 and will fall back on index 3. this is usually where the ipv4 address is on your device sometimes our ip address might not be the third index if on our windows device for instance my laptop does not give me that a correct address so in this case we will be using a for loop that will go through all the ip local addresses and checks if it begins with 192.168. this is the subnet we will be checking in and it's usually what home routers will use then we'll just set the ip address to the ip next thing we're going to do is we're actually going to connect some signals that connected the server signal and the server disconnected signal to our self the first thing we want to do for both of the signals is when we connect a server we just want print successfully connected and same for the server disconnected that way we can make sure we are actually connecting to the server in the debug now above this i'm just going to put in the create server code so it'll just make a new no multiplayer e-net which creates the server with the default port the max mail clients and then it sits the network pure for the tree which basically tells the scene tree that we're using this multiplayer e net and same for join server we're just going to make it our multiplayer e-net we're going to tell the create client at the ip address right here with the default port and that's everything for network code so next you want to hit project project settings auto load load in your network.gd as a singleton the next thing we're going to do is add a user interface node rename this network setup now we're going to add in our control node under that then we're going to rename this control node to multiplayer configure and we're going to set the layout to full rectangle then we're going to add a button and i also imported my fonts downhill.ttf you can find the all the assets in the google drive and you just import those by dragging them into here i'm going to rename this button to create server i'm going to set the text to create server now to add our custom fonts i'm just going to hit custom font so we need to make a new dynamic font so right click in file system new resource add a dynamic font we're going to name this dynamic font to base font in this dynamic font we're hit settings we're going to set the size to 64. we're check use mipmaps use filter and we're going to select the font data and drag it in which is our ttf file so now we have that font set up we can go back into our create server button drag in the base font all right next you want to hit layout and hit center now we're going to go 692.5 for the x position and the 338 for the y position we're going to set the size to 535 for the width and 176 for the height and that's our button now we can duplicate this and we'll call this join server and we'll set the text to join server now i'm going to go down the rectangle and set the height to 564. and there you go we have the two buttons then we're gonna add another node under the multiplayer configure we're gonna add a line edit we're gonna rename this aligning it to server ip address and we're gonna set the layout for this to center top and i'm gonna set the alignment to center i'm gonna set the placeholder text to enter ip address now go over the custom fonts drag in your base font for position 537.5 117 and for the size i'll do 845 104 and if the text is offset just change the placeholder text and that should fix it next thing we're going to do is we're going to click multiplayer setup we're going to add a new node add a canvas layer i'm going to right click on the canvas layer i'm going to add a label we're going to set the align to the label to center and the align of the label to center and then we're gonna add a custom font we're gonna drag in our base font i'm gonna click on layout we're gonna do bottom wide and for the size on this i'll set the position and the y to 930 and the size and the y to 150 which should align everything nicely now i'm just going to add a script to network setup and before we start adding stuff to our script click on your your create server button go to signals add the press signal back to the network setup and do the same for join server as well so we're going to get our multiplayer configuration ui which is just our multiplayer configure which is this right here in the scene tree then we're going to get our server ip address and our device ip address now we're going to connect the player connected signal the player disconnects signal and connected the server signal to our self and then in the ready function we're also going to add our device ipaddress.txt equals network.ip address this will set this it will set the text right here to the network ip address right now so we're going to do underscore player connected and underscore player disconnected and we're just going to program player has connected player has disconnected and their ids which these are the signals that are connected up here now when we create the server we just want to hide the multiplayer configuration ui and we want to tell the network to create the server now when we join the server we want to make sure that the server ip address.txt is not blank so we're going to be entering that ip address and make sure it actually has a text in it and then it will hide the multiplayer configuration ui and set the ip address equal to the text that you input into this field and then they'll tell the network to join the server and that should be all of our code this will establish a simple multiplayer connection so we can hit the play button and i'll just select this uh network setup scene and they'll run the game now to run the game twice i'm actually going to open another instance of godot and i'm gonna hit run and now we have two clients running so we'll create the server on this one and then on this one we'll actually join that server using the ipv4 address and we'll hit join server and it says player has connected all right thanks for watching if you guys are interested in more of my content or like this video feel free to subscribe helps me out a lot and i'll see you guys in the next one
Info
Channel: PlugWorld
Views: 26,472
Rating: undefined out of 5
Keywords: gamedev, godot, game, development, design, multiplayer, network, networking, shooter, topdown, io
Id: lpkaMKE081M
Channel Id: undefined
Length: 6min 20sec (380 seconds)
Published: Tue Feb 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.