Creating the Battle Royale Airplane | 09 | 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 Royale tutorial Series so in the last episode we set up uh steam so now the whole project is connected to steam and the sessions can now be run over steam uh so now that we got that out of the way we can now basically continue on the actual gameplay logic of the game so that's what we're going to be doing because in the video previous to setting up the steam video we basically uh made it so that when we hit play so just like this that in the top right corner we would see how many players are currently in the session and then it would say waiting for players and then once the uh required amount of player would connect we would get a countdown and after the countdown the session would start so if we tested that with two players super quickly and hit listen server then we see that we now have two players and that we got a countdown going on so here we go and the two beans they see each other and then we got three two one and then on the top left corner the server says started match so at that point what we want to do for this video is that we now want to spawn in the airplane to basically spawn somewhere and then fly over the island and it needs to be able to spawn in all different directions so sometimes the airplane might come from over here other times the airplane might come from over here and it just needs to fly a certain amount of uh distance and then after a while it will simply disappear and the players will have to spawn inside of the airplane and can then jump out over the island so um let's go ahead and get started on creating that so first of all I want to introduce you guys to some new assets again that I imported for the project so we got a new plane inside of the project so we quickly take a look at this then this is our beautiful Bean Battle Royale airplane it has a ledge and that's where the players can basically come out of and then uh next up we also have some audio and this is basically just a simple airplane Loop so this is just an airplane sound basically so in your typical Battle Royale game you basically get the airplane so let's simulate it real quick you get the airplane and it would be somewhere in the sky let's say here and then the airplane would basically F fly forward like this and you would follow the airplane with your camera and then it would say something like press F to jump out so when when you press F to jump out at that point your character actually spawns behind the airplane and then falls down and has the ability to open the parachute now the specific Logic for opening the parachute I will not do that in this video but we will actually build that directly in the next video so in most games that is basically how you follow the airplane so you follow the airplane like this and then you press F and then you spawn here as a character and then you basically fall out and land somewhere on the island uh and during that time that you are flying so during the time that your camera is positioned almost like this and that you're flying forward you are actually the plane so you are not literally a live character that is inside of the hatch you basically kind of possess the plane and then you basically just jump out whenever you feel like it so uh what we're going to do just because I think that's a fun idea is that we are going to actually spawn the physical beans inside of the airplane so what do I mean by that once the beans are ready at the start Island here and then go over to the airplane then I literally want to spawn the beans inside of this airplane where they can actually just walk around and look out like this and then they can jump out whenever they feel like it by simply jumping out so that I want to make it a bit more interactive like that and I think that's fun for this series so let's go ahead and get started and let's make sure that we can can spawn an airplane and that it will start to fly forward so to do that we are going over to our blueprint folder and then for the first time now we're going to have to create a folder called an actors folder so if we do new folder then we call this one actors and then inside of the actors's folder we're going to right click blueprint class and make a new actor so this one we're going to call it bpor let's call it airplane uh and let's go ahead and open it up then we can make this full screen and there we go so the first thing that we need for the airplane is the actual airplane static mesh itself so we're going to click here on ADD inside of the viewport and then over here we see static mesh you can also just type it in static mesh there we go then with the static mesh selected we can then put in the airplane here which is plane and there we go so that gives us our airplane and then what we want to do is that we want to make the static mesh the default root of this actor so we're going to Dr drag it in here to make that so uh so yeah now that we got this actor we basically need to make it so that the plane can fly forward so you can do that in a in a lot of ways of course you could actually move the plane forward using trust um and some kind of like physics basically or you could move the airplane forward using a timeline or using event tick but what we are going to do here is we're going to use something called a projectile movement so in essence we are going to make the plane a pro projectile uh why well it has some simple parameters for us here that we can adjust and it works pretty smoothly so with the projectile movement selected here we are going to be setting up some of the values so the initial speed that we wanted to move as let's put that at, 1500 is a nice value the max speed will also be500 now the projectile gravity we will set that to zero because otherwise the airplane will actually start falling down and then uh over here on velocity we also need to set its velocity so right now we see that it is set to X so it will basically move one unit on the x-axis each time but um if we actually drag the airplane into the scene like this then what we see is that the airplane is facing forward on the Y AIS so the Green Arrow here if we take a look under here under the transform details then we see that green is always the y axis we also see the little Gizmo here uh which tells us that green is the y axis now if you are to rotate the plane then green will still be in that direction but that is because we are now with the Gizmo in the world coordinates so to get that to actual local coordinates we can click here and then we see that indeed the green line is forward for this airplane now some objects that you export out of blender they might be aligned that the xaxis is their forward so in that case you would use x as your forward but for this one we use y as the forward okay so now that we understand that we can then go back back to the airplane and then since we put, 1500 as a speed then not on the x-axis in this case but on the Y AIS we're going to do, 1500 and we're going to set this X to Zero so let's go ahead hit compile and save and go to the event graph so with this setup we can now actually already start to take a look so if we drag this airplane into the world like this so just drag it from the blueprint here and then put it up then uh if we now hit play then the then the projectile movement component will actually just start moving the airplane forward so let's take a quick look at that we'll do one player Standalone and hit play so there we go so now we see that the airplane indeed starts moving over the map so that is all great and the speed if you want to have the airplane fly a little bit faster they can just up that, 1500 to be higher but I think this is a good speed now also previewing how far the airplane flies is a bit difficult in this mode so what we can also do if we click here uh on the three little dots then we can also not play an editor P but we can also simply click on simulate so if we do that we see how it will actually fly so here we can now see the airplane flying but then what we see in your typical batter roale is that well the airplane would spawn at something like this type of location and then it would basically um this is the end point where you would fall out so we need to make sure that our airplane doesn't just keep flying infinitely like this but that it indeed actually uh basically stops existing over here so to do that we're basically going to start measuring the distance that airplane has traveled and once it has traveled a certain amount of distance that we think is a good one then we basically want the airplane to remove itself so let's go ahead and set that logic up so to start off we need to get the starting value of the airplane actor so to do that we're going to right click and type in get actor location and then we're simply going to save this location as a variable so we're going to drag off of it click promote variable and let's call it the start location and then we can hook that up to the begin play so there we go but then we do have to keep in mind begin play on an actor runs on the server and on all the clients but this is only important for the server to basically keep track of this value so off of begin play we're going to drag off and type in switch has Authority and this way we can ensure that only the server stores this variable so now that we got that then the next thing that we need is an event tick and then on event tick we're basically going to be checking how far the plane has flown already and yet again only the server has to know how far the plane has flown so for this we're also going to copy paste the switch has Authority node over here and then we're going to drag in our start location and then in unreal there is a note called distance so if we drag off of the vector we can type in distance and there we go so what does distance asks for it asks for Factor one and Factor 2 so if this is location one and this is location two over here then it will basically return you what the distance is so for distance two we're going to get the actor location and now keep in mind here we store the actor location at the beginning and then on tick since the airplane is moving forward this actor location over here every take is going to update as well so this way we can now see how far we have traveled so let's go ahead and print string that so that we can actually validate that we're doing the correct logic so we plug this in over here and then we go ahead and hit play now we can check here inside of the viewboard we see that the airplane is then moving forward and here we can see how far the airplane has traveled so if we take a look at that we're already at 15,000 units 16 17 18 20,000 units so there we go uh and for you guys to understand how far that actually is inside of like a real world space 100 unreal units is 1 meter so then you can do the ma on how far you're actually flying and how big your your Island actually is so next up what we need to do is that we need to say after a certain amount of distance traveled we want to remove the airplane so what we're going to do is if the distance is greater or equal than uh some kind of value so let's start off with like 5,000 to see if this works then we basically want the airplane to destroy itself so in that case we're going to hold B and left click to get a branch and then hook up the condition hook this up to Authority and in the case that we have traveled more than 5,000 we want to destroy the actor so we're going to type in Destroy actor so let's have a look at that we're going to hit play airplane F forward and it destroys itself after 5,000 okay so that all works great so now we have a flying airplane that removes itself after a certain distance so that's great but now what we need in typical uh Battle Royale games is that the airplane would not always come from here sometimes the airplane comes from here and then it would fly this way over the island other sometimes it would come from here and it would fly this way over the island so now what we need to do is that we need to make sure that when the airplane spawns in that it actually spawns at a different location around the map so you could also do this in a lot of different ways you could set specific points uh that are just your preset points of where the air airplane could spawn in but what we're going to do is to keep it nice and modular and nice and flexible is that we basically want to have kind of a circle here and then the circle determines one type of point and that would be the entry point for the airplane to come in so how do we achieve something like that I came up with a with an ingenious plan that if you think of it as a little circle so if we would have a circle here and you would have a point on a circle and then if you would rotate the circle then you can basically get some kind of a location from where the airplane would need to spawn in so right now we're going to make that actor and that actor is basically going to be responsible for actually spawning our airplane so with the airplane selected we can go ahead and delete that from the world and then we can right click here in the content browser and click on blueprint class actor and let's call this one bpor airplane spawner next up we can open this up and that brings us to the viewport so inside of the viewport here we want to add a component called a spring arm so here we go then we want to make the spring arm the default scene route and then attached to this spring arm we want to put an arrow so we with the spring arm selected if we then type in Arrow arrow and hit click then we see that the arrow is over here now we want this Arrow to basically face down so that we know where we will spawn our airplane so let's make it look down 90° and there we go so what is this spring arm going to do well first of all we're going to make it way longer and then this location at the arrow is where the airplane will spawn in and then we will have this spring arm rotate to determine a point where the airplane would actually spawn in and then we're going to put this at the center of the map so at Z z0 of our map and that way we have like a rotating spawner for our airplane so for the size here we're going to have to eyeball it a little bit but let's type in something like um 30,000 and then we can drag it into the world to see what that looks like so right here we got our line we're going to set the x here to zero and the Y also to zero and then the height that will determine how high the airplane will spawn in the sky so let's put that to something like 8,000 there we go okay so basically the plan here is that this little spring arm will rotate like this and that then determines where the airplane spawns in so if we take a look right now at where the arrow is then it is over here which is pretty close to the coast so we're going to increase the size a little bit so let's make it 35,000 hit compile and save there we go okay so now that this is 35,000 that gives us this nice spawn point so this where we want the airplane to start and then we want it to fly over so now we basically know that in the airplane we set a distance for how far we want the airplane to fly and currently that we set that to 50,000 so since this is 35,000 here in the radius then we basically want to add another 35,000 for the airplane to fly so 35 + 35 makes 70 so we're going to have this be 70,000 before the airplane destroys itself okay then when we open up the airplane spawner here then we can start to actually code it so the first thing that we want this guy to do is to rotate so off of begin play we're going to do a switch as Authority again because we only want the server to do this the client doesn't need to know about any of this going on and then we want to set the actor rotation so there we go and for this actor rotation we're going to right click it and then we're going to split it because the only rotation that we want to do is the Z axis the Y and then for the ya we want to do it uh in a random float between 0 and 360° so if we type in random float in range that gives us this note which we can then hook up to the set so the minimum is0 degree change and the maximum is 360° change and then what we want to do is that we want to spawn the airplane so we want to spawn the uh spawn an actor from class and the actor from class that we want to spawn is our airplane here we go so this asks us for a spawn transform so if you then go ahead and make the spawn transform what we can also do is that we can right click it and split it that's a bit nicer 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 bye then for the location here we basically want to get the location of the arrow so if we have the spring arm we select the arrow hit F then this would be where the airplane spawns so if we drag the arrow into the scene here then we can drag off of it and type in get World location and then the world location is where we want to actually spawn here and for the rotation we also need to make sure that the airplane is facing the right direction so that it flies the correct way so for the rotation what we're going to do is that we're going to split it here and then we're going to say get actor location uh and now we want to basically calculate the location that the airplane needs to look at so on engine literally has a note for that that is called find look at rotation which asks us for a start position and a Target position so the start location would be the arrow and the target is basically the center of the of this of this actor here so the center of the airplane spawner so if we start here and then this is the end then we have a nice rotation that we want to look at and fly over so for that we can basically have the G actor location here uh because that is not going to change so even though we rotate the actor this spring arm is still going to be at this coordinate over here no matter how we rotate it the location will not change so um for this we're going to basically right click and split the rotation now the x is going to go in here and the Z is going to go in here and then what we saw is that uh well our airplane is exported on the Y AIS so we're going to have to compensate that by basically dragging off 90° here so we type in minus then we can do minus 90° you might not need to do this for your static meses but my static meses is exported on the y axis instead of the x-axis so I have to compensate that by removing 90° here this we plug in here and there we go so uh with this we can now basically compile and save and take a look so if we hit play it's going to immediately rotate spawn an airplane and then the airplane itself will just fly forward till it hits 70,000 and then it will destroy itself so let's go ahead and hit play we get our character here so there we see the airplane right now so the airplane is flying from the left into the map if we try that again then take a look at the map again then oh now it's flying over our head so that is pretty cool we can Al yet again click here on simulate and then we can run a couple simulations to see how it works so now the airplane comes from this direction and now from this direction and now from this direction Etc so that is uh basically what we need for the airplane spaw so next up we actually need to get our players into the airplane so if we go over to our airplane again then we can basically take a look in the viewport so so next thing that we want to do is that we actually want to spawn our characters somewhere inside of this airplane and since it's going to be a couple of characters cuz it's a multiplayer game they could spawn anywhere from here to there to there to there so we kind of need to get a random location to spawn it is what what you could also do is that you could put player starts here and have each player find an available empty player start but we can also just randomize it a little bit because it doesn't have to be that specific but before we do that we see that it's pretty dark in the airplane here so with the static match selected let's go ahead and add a quick little light so here we see a point light which is fine for me so we can add a point light yeah somewhere over there we can increase its intensity a little bit to make it a bit brighter and its radius perhaps there we go and then we can duplicate the point light to get another one and let's put this one somewhere over here now that we got a bit of light in here we can better see and understand what we're doing um so yeah how can we spawn our characters at a random location location inside of this uh inside of this cargo airplane well for that we can basically use something called a random Point inside of a bounding box so how can we code something like that well if we select the airplane we can click on ADD and we can get ourselves a collision volume uh because what we basically want to do is that somewhere inside of this volume is where we want to actually spawn our players so with the box here selected we can then give it a good size so first of all let's move it forward a little it so that they're kind of over here kind of and then we can move it down a little bit so let's do something like this yep that's fine and then it needs to be a bit bigger of course so we can do a 250 here on the X and then on the Y we can do something like 600 and for the set we can do something like 100 so let's say that this is the volume in which we want our players to spawn then how can we basically get some random kind of coordinate inside of that f volume so uh first of all yeah let's try it for one player so we need to then type in get player pawn and then the player Pawn we want to just set its uh set set actor location so here we go so we just want to set this guy somewhere inside of the airplane so how would we do that well if we type in random point in bounding box then we get this note so what does this note ask us for it asks us for a center and a half size so if we hover over the notes we can see what they mean by that so a random Point within a specific binding box using first Vector as a origin second as the Box extends so the Box extends if we select the Box we see that we made 250 600 and 100 so that's what we're going to type in here 250 600 and 100 and then we can plug this node in here and now for the center we just going to drag the box and that is just the location so we're going to type in get World location that's going to be into the center here there we go so now this of course will only work for one player cuz I just coded single player so if we do uh play Then There we go so now we see that the bean is actually inside of the airplane and that the airplane is actually flying over the island so this already pretty cool but now we just need to make sure that this works in multiplayer and hook it up to that event that actually starts the match when a certain amount of players are in the match at minimum so to make this work in multiplayer we're going to go back into here and now we need need to do basically the same logic but not just for the player Pawn at index zero but for all of the characters so what we're going to do is that uh let's go ahead and make a little function here we can call that function something like uh spawn spawn players in plane something like that and then the players that we want to spawn so if we type in get all actors of class those are our Bean players so that's our game play uh character over here so for each gameplay character we basically want to execute that logic that we have had made over here so if we then go ahead control copy delete it here go back to our function paste that logic here now for each player so each player like this we basically want to execute this logic and then you can also click on teleport that basically takes your physics with you and stuff so it's better to teleport the players so that's the logic now just make sure that we actually hook up our function so attach our function over here there we go so what does the airplane do well first of all the airplane spawner is actually first so the question is what does our airplane spawner do that is this guy uh well on the server we rotate it and then it spawns our airplane at the location of the arrow somewhere so that's it for this guy and then on the airplane here then the server will basically uh get a start location it will then start to automatically move forward because of the projectile movement component The Tick keeps track if the airplane met its end and will then destroy itself and at begin play the airplane spawns all of the players inside of a random location inside of this box that we defined in the airplane so there we go now last thing that we need to do in order to make sure that this all works properly multiplayer is with the airplane selected we go to class defaults and click on replicate to true so that the entire airplane is replicated properly and then we go to the airplane spawner and here we also need to click on class defaults and set replicates to true and then hit compile and save and then we can go ahead and close the airplane and also close the airplane spawner here we go uh then what we see is that well by default we have now put the airplane Spawner in the world here so we can either keep the airplane Spawner in the world or we can have the game State spawn the airplane spawner whenever the game state is ready so let's go ahead and open up our game play game State and then we head over to that function that we made in the previous video uh where we actually went over for the whole timer logic so if we open up our timer logic over here then we see in the end here that well only the server will do this that when the timer hits zero we say started match so at this point we basically need to spawn in our airplane spawner over here or we can also already pre-install the airplane spawner and just basically uh send to send an event to it that airplane spawner executes its first spawning event so we get the airplane spawner over here then we can open it up and then instead of having this be on begin play then we can make a custom event and let's just call this um spawn airplane and then we hook this up there we go and then inside of the game State we're going to get rid of this Noe that we had over here and then what we're going to do is get all actors of class now the class is going to be our airplane spawner airplane spawner uh um we will of course only have one airplane Spawner in the world so we could either directly drag off here and type in get a copy at index zero or we can also just for each Loop so for all airplane spawners that we will find in the world which will only be one we want to call this event to spawn us an airplane spawn airplane and there we go so now this is all properly set up and we should be able to have two players connected spawning in the airplane now there is one little thing that we forgot and that is that inside of the airplane we want to hook up some sound so with the static match selected we can click here on audio and we can click uh on the audio itself now for the sound here we want to plug in our sound cue for the airplane Loop and we also want to give it some uh attenuation so we click on override attenuation now we can see what the size of the sound is so is this a good size for us well we want it to be a bit bigger so that everybody can kind of hear it so let's make it uh something like this all right and then maybe this is too loud I'm not sure but that's all fine so now it's time to test first of all Let's test it with one player if we hit play with one player then we see that uh we are one out of two players so we do not meet the minimum amount of players required to play the game so it will just say waiting for players but then if we go ahead and test it with two players as a listen server and hit play and then we see the client here on the left spawning in now the client sees there's two out of two players and there is a 10-second countdown and on the right we see the server that also sees two out of two players countdown so in 3 seconds we're going to be spawning inside of the plane boom there we go both beans are in the plane now if we take a look over the edge here the plane is flying then if we take a look at the client here we see that the plane is indeed flying and that we spawned inside of the airplane so now we can go ahead ahead and jump uh into the Battle Royale and then the server also can jump into the Battle Royale and there we go now both players see that airplane flying there and then here we go now the client sees the airplane removing that has to do with the net Cur distance so the client is currently too far away from the actual airplane that's why it doesn't see it anymore so for the airplane we want the clients to actually be able to see it until the biggest distance uh and right now we also saw that the server deletes the airplane but the server now deleting the airplane is the airplane actually deleting and what the client here did is that if the client is too far away from the airplane then in on engine we got something called net cool distance which we can find over here by default it set to this High number but keep in mind you have to like this is the net squared distance so that's why it's such a high number and by default this comes down to 150 M basically so uh for the airplane we wanted to always be visible no matter how far away it is so if we want the airplane to always be visible for the clients as well then we need to click here on uh in the airplane blueprint on always relevant true so now that the airplane is always relevant the client can see it at any distance as well and why did the server see it and the client not well the the server is always relevant anyways for any replicated actor that exist inside of the world so the server the net calling distance does not apply to the server so now if we try it again we hit play let's just play it one more time okay there we go so we both spawn inside of the airplane client can then look over the edge I'll jump out here to make sure that we see the airplane going extremely far and then the server over here is going to jump out right now as well so here we go on the clients we see the little bean jumping out and then there is the airplane so now we will both See It Go off into the infinite distance but not really infinite cuz it destroys itself after it's traveled 70,000 unreal units so in a little bit now the airplane will hit the edge of the map there U and then it will destroy itself both the client and the server here we go and it looks like it's coming to the end now and there we go now the airplane is gone and at this point you would start properly playing your Battle Royale so guys that's it for this video I hope you liked it if you did then please be sure to give it a like And subscribe keep in mind guys the entire project files for this project are available on my patreon so if you want to get access to the project so that you can also use these assets that I'm using here or just want to quickly be able to go through the project or use the project for your own to modify then you can easily download it on my patreon I appreciate all of you guys watching in the next video we are going to be working on the parachute so the bean will actually have have the parachute or we might actually start working first on some finally some user interface that the bean actually has health and like a gun and things like that so let me know in the comments down below what you guys first want me to do the parachute or what you guys want me to start on the UI stuff and looting and guns and stuff like that all right guys anyways appreciate you and see you guys in the next one [Music] bye [Music] love
Info
Channel: Kekdot
Views: 4,589
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: c4yCk77G1l0
Channel Id: undefined
Length: 32min 41sec (1961 seconds)
Published: Thu Oct 26 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.