Creating the Replicated Parachute | 10 | Multiplayer Battle Royale | Tutorial | Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys quick heads up before I start the video the link down below takes you to my patreon where you can download the project files for this video also get access to my premium tutorials and in-depth courses where we build games together from start to finish check out my patreon below gain direct access to years of experience so that you can start working on your dream game tomorrow hello everybody and welcome back to a new episode of my multiplayer Bean battle real tutorial Series so in the last episode we set up the airplane so if I just click on two players here and hit play now we see that in the last episode we set up the airplane to actually be able to spawn so if we take a look at our two characters here we got our beans it uh the game notices that we got two players at minimum and starts a 15sec countdown after the 15-second countdown is ready we uh both get spawn into the airplane the beans can then stand on the edge and they can then jump out so I can go like and jump out of the actual airplane and then with the client here we can also now jump out of the actual airplane and there we go um but yeah what you see at your typical battery Royale is that you can of course jump out of that airplane and then have a parachute and use parachute so that's what we're going to be working on in this video now also what we set up of course is that the airplane spawns from all different directions so that's already very cool so uh let's go ahead and get started on making that parachute functionality so to get that started I want to let you guys know that in the assets folder here if we now go to props then we added a new prop which is the parachute itself so we're going to be using this type of parachutes now if you take a look at pubg uh there's there's like a rectangle type parachute so every game does it different of course but since this uh tutorial series is about uh how to code multiplayer and the general logic of multiplayer we I just decided to keep it simple and stick to this type of parachute so uh you do not have like an ability to hold shift to basically Start Skydiving down faster but we can actually steer and uh use the parachute so how does it work in some games sometimes you get that airplane it flies over and then you possess the airplane then once you press F your actual character spawns and then you can just press uh the parachute once to deploy the parachute what I'm going to be making is more the Call of Duty type setup where you can basically just use the parachute whenever you are high enough in the sky and then click the parachute button uh so you can basically just use the parachute not use the parachute use the parachute not use the parachute kind of like what you see in fortnite you can basically use the glider not use the glider use the glider Etc uh and uh we are basically going to be setting that up on spacebar which is also our jump button so that will automatically detect uh whether or not the character is high enough in the sky and then we will open up that parachute so for this we are going into our uh well we got our gameplay folder with our gameplay character here and we got the core folder which is the parent of this whole gameplay folder uh and what we're going to do is for this logic we're going to code it inside of the core character since the core character always needs to have the functionality to be able to use this parachut in this game so a couple things first if I click on one player Standalone and then hit play then we see that my camera right now is pretty much straight up behind my bean so uh that is okay but I want to change it a little bit so if we go over to the viewport then typically what you see in Battle Royale games is that the camera is a bit more offset so if we select the spring arm here then basically what I want to do is I want to put it up a little bit so let's say 100 and let's do it at something like minus 50 so that we're a little bit more to the right here and I also increased this length from 300 to 350 now of course you guys can just download the project files to this whole tutorial series and then can add it this as however you like but yeah this is kind of the camera angle that I'm going to go for right now and then once we start working on the gun in in a couple episodes from now then the the camera obviously has to zoom in and stuff then we will basically clean all of this up a little bit so now that we got this uh camera uh spring arm out of the way then let's go ahead and set up the parachute so what we're going to do is we're going to go ahead and click on the capu here and click on ADD and then we're going to be adding the static mesh and we're going to be calling it smore parachut so SM stands for static mesh then we're going to go over to the right and click type in shoot so there we go for the parachute we're going to hook it up so this gives us the preview of what that would look like now I do want to put this up a little bit let's say yeah something like this is fine and then by default we do not want this parachute to be visible so if we have the parachute selected then we can scroll down and then we see visible on rendering and we're going to turn that off and then we hit uh compile and save but what we also need to do is with this parachute selected here we also want to make sure that it does not have Collision so for the Collision up here we're also going to say to no Collision as what you typically see is that your character would have Collision but not the actual parachute itself all right so that brings us then to the event graph where we can now go ahead and start actually coding this so um to code this we want to do it on the space bar now space bar is our input action jump so basically if we hold space bar we want to parachute and then if we release space bar we don't want to parachute and then there should be some logic that checks if we actually can parachute or not so first all we're going to make ourselves a little variable here and what we call this is basically want to parachute question mark and what this variable does is that it's basically going to determine what we want so we're going to hook it up like this and like this then we're going to extend this a little bit uh so if you're pressing space bar then we want to parachute if we release space bar we do not want to parachute so now we as the client know that we want or don't want this but now it's also important that the server knows whether or not we want or don't want to parachute so we're going to right click here create a sh of custom event and call it Sr Set uh once to parachute so just like this and the SR stands for Server so with this event selected we're going to up to replicates and click on run on the server and we're going to make it a reliable event this ensures that even if there is a lot of networking data coming through that this event will still get executed even if you have a bit of lag and then what do we want to hook up to this event we also want to hook up the variable over here so that the server also knows whether or not we want to or don't want to so with the variable hooked up like this we can just get the value and plug it in like this and there we go then we can select it press C to put a comment around it and let's just say set once to parachute and in front of this we can write server set wants to parachutes just like that all right so not only do we locally want to know if we want a parachute as the offline player cuz keep in mind we are inside of the character class right now or being and characters exist on the server and on all clients so not only we want to know this but the server also wants to know this so to execute this we're going to type in Sr set wants to parachute now we could either just turn it on here or we can simply hook it up because then the value that we put in here get sent through and then we're going to do the same here so we're just going to hook it up like that and there we go so now we know what we want the server knows what we want so if we turn ourselves on right here then the server also is on and then basically we are in sync then next up we basically need to know if we actually can parachute so next to knowing that we want to we also need to know can we and we're going to determine that based on our height so how are we going to do that if we take a look at our Bean here then we basically want to calculate the height of the bean to the floor so we are going to shoot a line Trace straight down from the Bean that's going to determine how high the Bean is in the sky so let's say that our little bean is this high in the sky then we can say okay that's high enough at that point we allow the player to parachute whenever the player wants to but let's say that the bean is this high above the sky so only a couple of meters then we can say we don't want to be in Ed the parachute anymore so let's go ahead and make ourselves a little function like that which we are going to do here so under functions we're going to hit plus and then we're going to call this function can use par good question mark and then what we need to code here is the following so first of all we need to basically find our floor so how high we are away from the floor now unreal has a has a function for that pre-built so we don't you could actually say um line trace and actually shoot a line Trace yourself with some kind of logic to calculate the floor height but on engine already has a function built in for us so if we drag in the character movement component we can drag off here and type in find floor and this function if you over Hoover over it it tells you sweeps a vertical Trace to find the floor for the capsule at the given location okay so basically in simple this gives us um the the trace from the capsule all the way down to a floor so what do we want to put in here well for the Capal location we can simply type in get actor location and hook this guy up and then out of the result here we're going to drag out of it and click break which gives us the actual result of the hit and then out of here we're going to get the hit result and hit break going to collapse this then open this guy up and out of here we get a location so what's the logic that we're going to do here we're going to get our actor location so this is where we are in the world we're going to right click this the vector and split it and then what we can say is if we if we subtract our Z from the Z of the hit location then we basically know how high we are in the sky so out of location here where this line Trace impacts we're going to also break this one collapse this one again then we're going to say we're going to subtract ours with this one so that gives us how high we are in the sky so first of all let's go ahead and take a look at it so if I drag off of here and type in print string we get a print string and then I can hook this guy up here hit compile save and let's see what that does so in the event graph we're going to type in event tick hook this guy up like this and then we're going to drag our function here and let's have a look so if we click play then we see that we are now at 5.2 M all right then if I stand on the Rock we see we're still at 5.2 M so it actually does the correct height between us and and the floor but if I jump you see 400 300 400 300 and then something good to keep in mind is that 100 unal engine units is basically a meter so if I'm jumping right now then the game tells us I'm jumping 3.7 M which is of course that would be extremely high in real life but in a game like this everything is a bit distorted so apparently we are now jumping 500 so 5 m high and then 3 m so yeah there we go so what we can see inside of this function uh because this function does determine if we can or cannot parachute is that if the amount that comes out of here is bigger greater or equal so if you're typing if you just do a little this symbol here to the right and then you can type or you can either just type in greater equal then you get this and then we can say if it is above 2,000 we can parachute for example so you could adjust this parameter however you like but I'm going to say 2,000 so what do we want to return on the function uh if we click the function we want to Output whether or not we are above the 2,000 and then we say we can parachute or we can't so this parameter here we're going to change it to let's say can parachute question mark and we're simply going to hook this up so right now if we then hit uh play or sorry if we first print string this print string and then put this into here then if we hit play then right now it tells us false so now I can't parachute cuz I'm not at 2,000 units so 2,000 units how high that at minimum that's 20 M basically since 100 is 1 M 2,000 is 20 M but then what we can test is if we have the viewport open here we can click here and click on current camera location as our spawn location so now if I go high in the sky and then click on play then we see true true true true true true true false so there we go so now we got a function that basically calculates for us if we can or cannot use the parachute but then we do see that this function is an executable function and what we rather have is that this function is a pure function because all we need to know is whether or not we can we don't really have to have it have execution pins so if we select the function over here or on the left you can also select it here then we can click on pure and that gives us this beautiful little note which just returns us the value that we want to know so now that we know whether or not we can parachute then we're basically on tick going to check if we want to parachute and if we want to parachute and we can parachute then we're going to parachute but if we don't want to parachute then we're not going to parachute so what we're going to do right now is make a new variable which will basically determine if we are actually parachuting so we can basically just call this um is parachuting and we can add a question mark behind this one okay so first of all on tick we need to check do we want to parachute so if we hook this guy up like this and we got this logic now if we do not want to parachute then we can set that logic up very quickly so if we do not want to parachute then we're just going to do a simple check to say okay I don't want to parachute but then in case that I am parachuting then we're simply going to turn it off so this is all the logic that we're going to do off of false so if I don't want a parachute but I turn out to still be parachuting then we make sure that we are not parachuting and then it basically turns it off in in one tick and then all the rest of the ticks are just going to go out of here and not going to consume much for us uh and then basically up here we're just going to say okay if I want to parachute then how can we determine if we are parachuting by determining if we can parachutes so that's the logic that we want up here then if we select all of this we can put a com around it and just call it parachuting logic something like that so how do we then actually make that parachute visible well both the server and the client execute this tick for this character so now that the server and the client execute this tick then we can also say okay if the server executes this logic as well then we can make this one a rep notify and as I explained before what a rep nodey is is if the value is set in a rep nodey it executes a corresponding or basically an attached function so what we're going to do is if we are parachuting then we want this rep notified to be responsible for actually showing us the parachute but not only that we also want this rep notify to then be responsible for actually giving us different types of values over here so that we can start gliding so first thing that we're going to do is Select this variable and make it a w notify then we're going to hit compile and save and there we go and then the next thing that we do is that we know that a rep notify executes on the server and on all the clients so if the server basically sets this one up then this function that it is attached to this function over here will automatically execute so the first thing that we want to do when this function executes and if it is set to true or false is that we want to set the visibility of the parachute static mesh so this guy so we're going to drag it in and then what whatever we are going to attach in this new visibility is whether or not we are parachuting so we're going to hook it up so we can already go ahead and give this a quick little test so to now test this out what we're going to do is that uh well first of all we had our setting here to to spawn at the camera location we're going to spawn it at the default location again then we're going to set our number of players to two and this time we're going to play as listen server that we can test with the server and the client uh so let's actually just make them go into the airplane so here we got our two little beans they can see each other so on the right here is my server on the left is my client right now they cannot parachute so that's great so let's wait till this is done and boom okay so both of my beans are in the airplane we're going to put them both on the edge and see if they can see each other uh actually using the parachute so the client is going to wait here first uh and then the server is going to jump out so here we go boom and the client doesn't see the parachute but does the client see their own parachute and does the server see the client parachute so let's look at the airplane here comes the client oh yep so the server does see the client parachute but the client does not see the server parachute so if we go into our uh into our character here now we can quickly see why that is you guys can probably already guess it as well that is because we need to replicate this variable so if you select this variable set it to replicate then everything is properly replicated so how come that the server could see the client before this was replicated but the client not the server well in case that you are the client the client exist on the server and on the client itself the server only exists on the server so basically what that means is if I am the server and I'm doing it I'm putting this to true and then I'm putting this to true but that means that the client that's going to execute the event TI for the server character on the client side instance will never know that this is true and because of that it will always go off of false and never display that parachute even though it's getting updates from the server with the r notify here it will basically just keep saying that it's not true because we locally set it to not be true so uh and then how can it be that the server can see the client's parachute well in case of the client the client would basically just set it locally and set it on the server so because the client did send it to the server but the server not to the client then the server could see the client's parachute and the client not a server parachute so to make the client also able to see the server parachute we need to set this variable to be replicated since now if the server basically does it locally and executes it on the server then at least the client via replication will get it here and will be able to execute this eventi Logic for that server's character in their own local instance and now the client executes it locally and on the server that means that the server and the client are basically agreeing with each other that we want to show the parachute and then it would also work so by simply setting this one to replicate it and then if we hit play then we can test it once more to see if they can see each other's parachutes so here we go in three 2 1 into the airplane okay so we're both going to stand on the edge again and then here's the server on the right so the server is now going to Simply jump out and hold space bar client sees the parachute then the server is going to look at the airplane client is going to jump out and the server also sees client parachute so now everybody sees everything and that's great so now we go to the last part of the puzzle which is basically making sure that we can actually float so as we see we're falling very fast right now so to do that we're also going to go back into this function which is responsible for us actually parachuting and we're going to do the following logic first of all we're going to check if we are parachuting or not uh so if we are par shooting then we basically want to say that we change our velocity so that we can kind of feel like we're gliding so instead of messing with the gravity and other types of settings we are going to basically just manipulate the Vel vity so that we go less fast and if we go less fast then that's basically what an parachute does for us so what we're going to say is we're going to type in get velocity and then we're going to rightclick the vector and hit split and then out of the Z here comes to Velocity for us going up or down so in the case that you're going up your set velocity would be positive it could go into the thousands if you're going up very fast now in case that you're going down like jumping out of an airplane your set velocity will be negative so this will be like minus1 all the way to maybe - 5,000 depending on how fast you fall so what we're going to be saying is that we do not want to fall super fast check out cact center right now steam in Early Access it's a very fun multiplayer video game cheaper than the Starbucks coffee so if you want to have a good time with your friends or strangers click that link down below and I appreciate every single one of you and enjoy the rest of the video [Music] bye so first of all we need to get kind of an idea of how fast we're falling so what we're going to do is drag out of here and type in print string to kind of have an idea of how fast this character is typically falling so to do that let's do one player Standalone go here click here current camera location let's go all the way in the sky and see what it print strings so if I'm falling and I hold space bar it will just say hello hello hello that's because we put it into the duration obviously this needs to go here in the string so if I'm in the viewport and then hit play we fall out the sky we see I'm falling at minus 4,000 so at maximum speed because with gravity and mass of course a character will sometimes reach a maximum uh falling speed right we see that it goes all the way from 2,000 - 3,000 to - 4,000 okay so that's a pretty high value so what we're going to do is that we're basically going to say if we are less or equal then let's try - 750 in that case we want to slow the velocity and clamp it between 750 uh but minus 750 and zero so to do that we're basically going to get our velocity and then if we grab our character movement component and drag out of here then we can say set velocity and then we get this note and then if this is true so if our speed is basically lower than -750 which means we're falling faster 750 so this would be - 3,000 - 4,000 Etc that would all come out of the true here then in that case we basically want to overwrite the set velocity to be lower so we're going to right click this now for the X and the Y we do not need to manipulate those velocities so we're going to put those back in but for the Z we're going to say let's clamp it so clamp float and then we're going to hook this up and then we're going to clamp it uh between minimal uh 750 and Max uh let's say zero so if we are going 3,000 uh down so that means- 3,000 then let's make it at minimum 750 but let's say that we're already going very slow so we're already going minus 400 then it is just between these values of RS so then we say okay that's fine then we just keep at the value that we're already going at so this should actually slow us down and it should visualize the effect of us being able to jump like a parachute so right now we're going to basically just uh hit play here I'm falling falling falling falling and I got a pretty high velocity I get my little parachute and there we go so now I got a pretty nice Glide I get close enough to the floor and the parachute automatically cuts off so there we go guys that's basically how we made a multiplayer uh parachute now we're going to go ahead and give it one final little test so we're going to hit save all then we're going to click two players listener server and we want to spawn at the default player start and hit play so here we got the little server Bean on the right client Bean on the left and we got the countdown going okay so three two one and into the airplane so now we're going to put them both on the edge so we're going to put our server on the edge here like this and then let's also put our client on the edge here like this so first of all we're going to jump with the server we're also going to have to check if it's actually floating like a parachute so here we go and fly then I can release do it again and release do it again and then when I hit the floor it's going to cut off there we go and now it's time for the client to jump so here we got the client jumps out and flying it's very smooth and then we let go hold space bar and it's super smooth so there we go that's basically how we made a cool replicated parachute with actual gliding logic as well so so that's great um yeah so that sums it up guys that's basically it for this video now if you do want the airplane to be able to fly higher then what we saw in the previous video is that we set up this airplane spawner with which we go to the detail panels we see it's at 8,000 so what we could do is that we could increase this to say 15,000 uh just like that so then you have a little bit more room to actually fly which is fun or we could maybe just increase it to 20,000 so that we fly a little little bit higher so let's do it one more time cuz it looks so cool so let's do two players here we go play this time I'm going to make the windows a bit bigger so let's put this one here this one here okay so 5 4 3 2 1 and there we go so we're both inside of the airplane we're going to stand on the edge this guy is also going to stand on the edge so and then we hold space bar we see the server gliding and this one goes down lower lower lower lower and then I'll do the space bar again and then we can land somewhere over here then we're going to look up at our other little bean this guy is now going to jump out woo and parachute and now we see this guy parachuting as well so yeah it looks pretty funny it's a nice mechanic it's very smooth also so that is it for this video guys now be sure to check it out on the patreon if you want to get access to the project file so that you can play with this yourself or change it everything a little bit maybe you want to swap out the Bean with an actual character right and feel free to do all of that so guys that was it for this video if you liked it be sure to hit the like button and subscribe that help helps out the channel a lot I appreciate you guys and I'll see you guys in the next one [Music] bye [Music] me
Info
Channel: Kekdot
Views: 2,943
Rating: undefined out of 5
Keywords: Blueprints, Unreal Engine 5, Unreal Engine 4, Steam, Multiplayer, Game, Marketplace, Lobby, Game development, Unreal Engine, UE, Multiplayer game, Host game, Sessions, Lobby system, Advanced, Tutorial, Server browser, Sessions Steam, Ready up system, Online, Multiplayer Unreal, Replication, Replicated, MMO, Subsystem, Game Engine, Solution, Modular, Devlog, Listen server, Dedicated Server, Seamless travel, GameMode, GameState, PlayerState, PlayerController, Widgets, RPC's, Steam advanced session, Plugin
Id: zl0ozQFtD9U
Channel Id: undefined
Length: 28min 5sec (1685 seconds)
Published: Sat Oct 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.