Godot Multiplayer Tutorial - How to Make a Server Map | Godot Dedicated Server #17

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this god.multiplayer tutorial we're going to be making a server map so that we can do some server-side physics let's get started i'm here on the client project and i'm looking at the client map the client map is responsible for all the coalition detections whether an ice spear hits a web air or whether a player bumps into a tree we don't want these coalition detections to be done on the client because that is inherently exploit sensitive we need to be making a server map and feed the server with coalition data so that the server can take over all the coalition calculations in order to do that we're first going to extract the coalition data out of this map make it a server map then we'll do the same for the isphere and the weber so we can see some things going on then in the next video we'll work on the actual coalition detection server side and the calculations for that server side to get started with our server map i'm first going to be pulling a duplicate of the map that we have here on the client i'm gonna right click my map.tscn and i'm gonna select duplicate i have to give this a name and this name needs to be different than the original map it doesn't really matter how you name this map you can always rename it later once you've moved it to the server so in my case i'll just call it server map so i can easily distinguish between the two i'll open up this server map that's extremely important they're going to look identical so it's really easy to make some accidental changes on your original map and that's of course what you don't want it's a good practice to just close this map all together so you only have to duplicate open now with that done we have to consider what the server actually is going to need it's not really going to need any textures because well nobody's looking at it in fact the lighter that we can make this the better because it will make the server executable smaller and it won't have any baggage so for example a graphical user interface with a login screen our server doesn't need that it's players logging into the server server's not going to log into itself so we can remove that and tiles we don't really need tiles tiles are just for visual fidelity they're not here to make the server happy they definitely don't have any coalition data unless of course you put collision data in your tile maps then you do need to keep them i don't have any collision data here so i'm just going to delete them i'm going to remove this back fix and i'll remove my main tiles and then we are left with this well we also don't really need any trees so let's open up our trees and let's just delete all our tree sprites and let's keep that coalition shape of course and we need that static body we need a coalition polygon but we don't need the actual texture then we have a player here but that player is here because the client always needs to have a player a representative of the player that's actually playing the game but the server is not participating in the game the server only runs the game so we don't really need a player either and yeah it's handy to have a y sword container for some enemies that the server is going to be spawning in and if we want coalition detection between all the players then it's good to have a y sword for that as well but yeah this is actually all we need then on the map it currently has a script but of course the script on the server is going to look completely different so may as well disconnect that one and here you have it we all we really are left with is a bunch of containers and some coalition data in this case our four coalition polygons where our trees are so let's save this and now we're going to be putting this on the server putting this map on the server is actually a breeze all we got to do is copy paste it i'm right here in my directory where i got my four folders for the four different projects for this tutorial i'm going to go in my clients scenes main scenes where i have my map and server scene as you can see the server scene is considerably smaller than the original map scene that stays on the client 25 versus three kilobytes but the biggest save is of course in all the textures all the sprite sheets and all the tile sets that no longer have to come to the server those easily add up to megabytes so in total we have reduced the size of this server map by probably more than a factor of a thousand so that's a big win right there i'm going to be copying this server map i'm going to go back to all those projects and go to my server project and here on the scenes and i've created a new map world i'm going to be pasting it in as you can see i've already got it along with my server weber and my server i spear as i've of course prepared a little bit of for this tutorial now with it in here we can have a look at the server project and what we're actually going to do with it there i'm on the server project now and as you can see by the note 3 we now have the world map which is an instance of that servermap.tscn our three coalition polygons have now popped up on the screen this scene loads in without any issue without any broken references because there's no references in this scene anymore there's no references to textures no references to sprite sheets no references to resource files for the tile set no tile set textures that it requires is basically an empty shell with just a couple of elements that are native to godot the coalition polygons are native the static body to these are native and a couple of containers node 2d and y swords are native to gold as well so any project that you put this scene in will load it up automatically now if you require some of those textures maybe because your tileset has a lot of coalition data you have to make sure that in the file manager you set up exactly the same note structure put your textures and possibly your trust files in there as well and maybe when you load up the map or load up the scene it may come up with a pop-up that it cannot find certain references and you'll have to fix those references however the leaner you can make your map the more empty you can make this and the further down you can get to just the bare bone minimal coalition data the lighter it's going to be for your server and the faster it's going to be for your server now that we have this world map here which is the server map you of course also want to know how to make this server ispir and the server weber so let's get into that and then we'll continue on with actually putting this onto the map and seeing our coalitions move around i'm back on the client project and i've pulled a duplicate of both the ispear and the weber so these are these two scenes on the top here and we're going to be reducing these two scenes together to their bare minimum so for the ice pair we definitely will not require any sort of animations because nobody is looking at this so we can definitely delete the animation tree and the animation player for the sprite it's exactly the same we don't need any of these visuals on the server all we really care about is the collision data so also for the sprite we will be deleting this that keeps us with just a rigid body 2d and a coalition polygon which is perfect for our server now we also have a server uh or a signal sorry and a script of course the script same story we're gonna be deleting that the script we're actually going to be requiring to spawn this is going to be very similar but i prefer to pull this scene from one project to the other project without any references to other documents that it might start to be looking for otherwise we might have broken links and i prefer to just make this copy past as clean as possible from one project to the other to ensure i don't get any bad bugs or weird glitches or something like that same is going to be for the signal i prefer this to just be disconnected so it is as clean as possible and just like that we're going to be putting it on the server now i'm gonna not gonna be showing you how i put it on the server again because that's of course just a repeat of that copy paste that i just earlier i'm pretty sure you can do that by yourself so now let's switch over to the server where there well it has a health bar but who really cares about his health bar the server already knows the health of the weber and that's simply an integer a data point and a dictionary that's not required to be on the screen nobody's looking at the server for the animation player same story don't need that the hitbox that one is important because the hitbox is where the collision detection is taking place between this weber and for example an ispear so we're definitely going to be needing to keep this hitbox here sprite same story let's delete it now the weber is currently in a group we might need that group again on the server for now we're just going to delete it we'll add that group again on the server side if we really need that script same story we're going to be deleting it and that's it that's how we're there and as you can see this wherever is going to look exactly the same as for example a skeleton might look or maybe a squire or a knight or a spearman would look like if you have one size for a humanoid kind of creature and although there's not really a humanoid it's pretty much almost the same you can probably use the same setup hitbox and coalition polygon for pretty much any humanoid kind of character that you may have of course if you also have a dragon you'll probably need like a specific big coalition shape for that one but yeah you can probably figure out how you can pretty much optimalize this code and these scenes by a lot by not naming this a server but just naming this an enemy or a standard enemy or a humanoid m me on the server you need much less scenes that way so with that set we'll save this one too i'll bring this over to the server project or actually i already have as you saw and then we'll move on actually spawning some ice pairs and some wear theirs i'm now on the client project and i'm looking at the player script on the player script we have our function attack which does two things it instances in an i-sphere for this client and it communicates to the game server that has attacked so that the server can update all the other clients or inform all the other clients to instance in an isp as well now on top of that we also want the server itself to instance in a server version of that ispear so it can start taking over the coalition detection system we do that by pushing three more variables into this function and those are going to be the impulse rotation position and direction now we don't want these value definitions which are already pretty long lines by themselves to go into this single line because that would make an ultra long line difficult to read difficult to maintain so we're first going to be defining these value definitions into variables that we can then push into the game server send attack function we do that as such we simply still instance in an isp for this client but we first define that rotation position and direction into variables with those variables we can make the game server send attack hole and we can push those a rotation a position a direction in there where we previously had three four five that were just placeholders and of course we can use the same variables now push them straight into our sphere instance we don't have to read those redefining those values again so with that done we can now have a look quickly on the game server script which is going to get that send attack function and send attack now is simply going to be receiving that rotation position and direction and it's going to be pushing those values into our rpc call which is then send off to the server switching to the server we can now see on our game server our main interface that remote function attack is going to receive those variables and it's not going to do anything with those variables in terms of sending it to other players that's not required we already programmed how other players are going to spawn all those instances in what we can do now though is that we now can we can get the note world map where i've added a script to we can run a new function spawn attack we're going to give it a spawn time and the rotation position direction and the player id because we do want to know which player has hit anything so that we can award the right player with for example experience points so the spawn time here is something that i won't be using in this tutorial but it could be something if you want to sync up the time of this ice spear so you can put the timestamp on the ice sphere but of course there's a little bit of latency between the player and the server if it is absolutely crucial for your game especially related in pvp then you might want to sync up that i spear so that it flies out either a little bit faster or it immediately catches up by going forward a little bit for whatever time it was spawned into the world already that way you have more precision which is more important for pvp i won't be doing that here right now because now we're just dealing with a still standing where there really so on the world map script so let's go to the world map node that new node the map node we got a new script here and here let me close this one we'll get into web in a moment we got the spawn attack it's going to receive those variables and here you can see we do something pretty similar to what we have been doing on the client side we simply define a new instance of the i sphere which is a pre-loaded scene right here we're going to send that player id so that player id is a new variable on the i sphere so when the ice spear hit it knows which player that i spear originated from so we can reward experience points and stuff like that we push that impulse rotation position and direction exactly like we did on the client and we add that child to the world now let's also have a look at the actual ispir code to see how it actually starts moving the ispear code is almost a one-on-one copy of the code that used to be on the client side as we pretty much want the behavior of the i spear to be identical to what the player sees otherwise we're going to get weird artifacts so this of course all set on the code we just had a look at the player id is the only thing that's different compared to the client side of the script under the ready function we have that same apply impulse function we are starting the self-destruct function to make sure that it self destroys the scene after the lifetime of three seconds we point the collision shape in the right direction we have commented out the set damage function for now that's going to be something we'll be implementing in the next tutorial we have the self-destruct function and of course our function on isp body entered doesn't trigger right now as we've taken out that signal we have disconnected that we'll be reconnecting that up in the next tutorial when we actually do the collision detection system and start doing the damaged part entirely on the server so that the client cannot get in between there now we have an ice pair that's going to be spawning in but of course we need some wear bears so let's first make sure that we spawn these werebears in as soon as we got them spawned in we can do a quick demonstration now our enemies are going to be so much easier because we don't even have to go from the client to the server because the server is authoritative so the server decides when an enemy spawns and where an enemy spawns so we're going to go to the map script where we have our function spawn enemy with our randomization which selects a random enemy puts it at a random position within a spawn timer right here once we have defined our enemy we are putting it in our enemy list that enemy list at that point contains all the data we require a position an enemy type if you have different coalition shapes and an enemy id so we know which one we are hitting or which one we are killing in our collision system right here we need one extra line of code we're simply going to approach that world map node again we're going to run the function spawn enemy in my case i've only added the enemy id and the location and not the enemy type as i only have one scene for enemies if you have a game where you only have humanoids and you can make use of the same base format for an enemy in terms of coalition shapes then you don't need to push the enemy type if you got different enemy times with different sides and shades chases shapes and different hitbox sizes then of course you will need to communicate that type so that the correct scene can be instanced in now once we have that spawn enemy we go back to our server map we have a function spawn enemy which is going to pull off a new instance from the pre-loaded scene of that server where there is gonna set a position it's gonna set the name as the enemy id and we are simply going to be adding it to our y sword enemies just like that we have our coalitions now on the server so let's give this a spin now let's have a look at the server as you can see our weber has already spawned in you can see the coalition shape right here we don't see this on the client yet because the client hasn't logged in now we'll log in the client and as you can see the weber is there it already lost some health now if i were to shoot an isp you can see on our server that we have our aerospare coalition shape moving out and as you can see we can have this i wear there just like as well we can hit it on the server we can hit it on the game on the game it currently dies because it does the hit detection still we haven't broken that out yet and on the server it remains because simply we don't have the hit detection on the server yet so we don't know when to despawn though i haven't colored that in it's going to be the next tutorial there's one thing that i want to point out here and that is that the ispears have a certain choppiness to them on the server that choppiness is a result of when we created the very first state processing when we process the world state when we did that we set the actual frames per second of the physics engine to 20 instead of 60 and as a result of that change these ice spheres are now also being updated with 20 frames per second in some games this can be enough as the projectiles move either very slowly or maybe it's turn-based and at that point you're absolutely fine if you got a little bit more of a high speed or a higher pace game you might want to change that so that the coalition shape is updated more often and cannot glitch through walls or something like that because it has transversed the wall before the actual update of the collision shape took place so i'm going to show you really quickly how you can make sure that these ice spears update at 60 frames per second but the world state processing still happens at 20 times per second to make these changes of course first have to go into my project project settings under my physics section in the common tab i'm going to move my physics fps back to 60. now in my state processing part i'm going to be adding a couple lines of code here i'm going to move this one up with indentation i'm going to add this code with this extra variable now we have a sync clock counter which starts at zero and every time the physics process function runs which now runs at 60 frames per second again we're gonna add one to that clock if that clock hits free we're gonna reset it back to zero and here we're going to be playing that world state syncing process in other words 60 divided by three we now have 20 frames per second again on our world state processing while we do have those 60 frames per second for our i spear so now the ice spears are going to look a lot smoother to give that a super quick demonstration i'm back here on my project and as you can see the ice spears are no longer as choppy as they used to be as you can see they already find the coalition with our best but we don't actually do the collision detection yet we don't have any signals set up yet we don't do any on-hit functions yet we don't take off any health yet on the server side based on this coalition and of course we have to break out all the correlation detections that happening on the client so the client loses his exploit possibility so that's going to be up for the next tutorial i hope to see you there that was it for today guys hope you liked this video if you did smash that like button hit subscribe don't forget that little bell icon to make sure that you don't miss out on the next video where we're going to be completing this server-side coalition detection system until then keep on gaming keep on coding see you later guys
Info
Channel: Game Development Center
Views: 4,122
Rating: undefined out of 5
Keywords: Godot Multiplayer Map, Godot Server Map, Godot Multiplayer Syncing, Godot server collisions, Godot multiplayer exploits, Godot avoiding exploits, Godot avoid cheating, Godot how to make a server map, Godot Network, Godot Networking, Godot Dedicated Server, Godot Multiplayer Server, How to make a multiplayer game, Godot MMO, Godot Beginner Tutorial, Godot 2d Tutorial, Godot Tutorial, Godot
Id: fU9VHp-kmqM
Channel Id: undefined
Length: 19min 49sec (1189 seconds)
Published: Sun Jan 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.