Unreal Engine 4: Create Your Own First-Person Shooter | Tim Lash | Skillshare
Drawer
Search

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Unreal Engine 4: Create Your Own First-Person Shooter

teacher avatar Tim Lash, YouTuber & Game Design Instructor

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Course Trailer

      2:14

    • 2.

      Introduction & Project Overview

      10:56

    • 3.

      Download & Install

      2:21

    • 4.

      Setting Up Our Project

      6:20

    • 5.

      Making Our Character Move

      9:28

    • 6.

      Adding Content Packs

      6:04

    • 7.

      Creating the First Person Character

      10:59

    • 8.

      Animating Our Character

      13:40

    • 9.

      Equipping Our Loadout (Part 1)

      19:59

    • 10.

      Equipping Our Loadout (Part 2)

      18:02

    • 11.

      Creating Weapon Pick Ups

      26:14

    • 12.

      Making Our Own Weapon Animations

      27:58

    • 13.

      Switching Between Weapons Animation

      7:51

    • 14.

      Dynamic Crosshairs

      27:27

    • 15.

      Creating the Main HUD

      21:37

    • 16.

      Sprinting Functionality

      23:07

    • 17.

      Adding Sprinting Animations

      10:42

    • 18.

      Making Ammo Pick Ups

      20:49

    • 19.

      Shooting Hit Scan Weapons

      24:47

    • 20.

      Reloading Functionality (Part 1)

      19:44

    • 21.

      Reloading Functionality (Part 2)

      23:20

    • 22.

      Reloading Weapon Animation

      10:37

    • 23.

      Shooting the Pistol

      3:13

    • 24.

      Adding Realistic Recoil

      9:16

    • 25.

      Shooting the Assault Rifle

      8:06

    • 26.

      Shooting the Shotgun

      16:01

    • 27.

      Creating Impact Effects

      26:41

    • 28.

      Damaging Enemies

      27:21

    • 29.

      Aiming Down Sights

      20:53

    • 30.

      ADS Camera Zoom

      9:51

    • 31.

      Adding Hit Markers

      13:28

    • 32.

      Adding Damage Numbers

      22:04

    • 33.

      Enemy Defeated Animation

      12:30

    • 34.

      Shooting Projectiles (Part 1)

      22:46

    • 35.

      Shooting Projectiles (Part 2)

      13:42

    • 36.

      Shooting the Sniper Rifle

      12:09

    • 37.

      Making Things Go BOOM (Explosions!)

      17:48

    • 38.

      Shooting the Grenade and Rocket Launcher (Final)

      16:06

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

1,313

Students

2

Projects

About This Class

In this game design course, I’ll guide you through the process of making a first-person shooter game! This course uses Unreal Engine 4 — the same game engine AAA games development studios used to make Fortnite, Batman Arkham Knight, Borderlands, and many others!

This class contains 38 video lessons that will walk you step-by-step through the following topics:

  • How to create 6 customizable weapons (includes pistol, assault rifle, shotgun, sniper rifle, grenade launcher, and rocket launcher)
  • How to make hit scan and projectile based weapons
  • How to animate a first-person character
  • How to script complex reloading and shooting systems
  • How to spawn dynamic impact effects
  • How to damage enemy characters based on specific body parts
  • How to create interactable ammo pick up objects
  • How to construct a player HUD using Widgets
  • How to add realistic particle and sound effects to a game
  • And much more!

With the knowledge you’ll acquire in this class, you’ll gain an in-depth understanding of first-person shooter mechanics. This knowledge applies to all kinds of genres, such as looter, survival horror, military, sci-fi, and others, allowing you to take this project in an endless number of directions! While anyone is welcome to take this course, I recommend it for those with at least some coding knowledge or experience using Unreal Engine 4. While my lessons are thorough, I do not take the time in this course to explain the absolute basics of coding and Unreal Engine 4. If you are completely new, I recommend you take my course on Third-Person Action Adventure games first.

Meet Your Teacher

Teacher Profile Image

Tim Lash

YouTuber & Game Design Instructor

Teacher

Hi, my name is Tim – but some of you may know me better as Timbo from my gaming YouTube channel with over 130,000 subscribers! Outside of making YouTube videos, I work at Epic Games on the popular title, Fortnite! Over the years, my creative passions have turned into real, practical knowledge. Game design and other creative fields are within your grasp, no matter where you're starting from. With my classes, I hope to help further your knowledge and kickstart your journey!

See full profile

Level: Intermediate

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Course Trailer: One of the most popular genres in modern gaming is the shooter. Trust me, I google this cenotes legit within the shooter genre comes at plethora of sub-genres. Looters like Destiny, military-like battlefield and Call of Duty, C5a, halo arena, like Overwatch, survival Horror, Resident Evil. The list really does go on and on. This class aims to teach you the fundamentals of advanced first-person shooter mechanics, enabling you to create any shooter game of your choosing. Hi, my name's Tim, but some of you may know me better as timber for my YouTube channel with over 130 thousand subscribers outside of making YouTube videos on my favorite games, I currently work for Epic Games, the makers of the Unreal Engine on the popular battle royale game Fortnite. In this course, we will start with a completely blank template to transforming it into a robust first-person shooter, we will create six fully customizable weapons each but their own sounds, animations, reload times, bullet spreads, recoil intensity, impact effects, ammo pickups and more. I will show you how to mimic game, such as Call of Duty, using invisible line traces to generate dynamic hit events, other weapons will mimic more realistic titles such as battlefield, that shoot actual projectiles out of our guns, allowing us to customize our bullet speed and gravitational force. We will cover how to blow things up with grenade and rocket launchers. We're even going to make an enemy class that dynamically response to damage depending on the body part we hit festival. Every asset used in this course is 100% free, as we will be using Unreal Engine 4, the same game engine used to create these popular AAA titles. While this class can be taken by anyone, I recommend it for those with at least some Unreal Engine coding experience, as most of our work will be done scripting in blueprints. So if you want to take your unreal skills to the next level, or you simply want to learn how popular shooter games are created. Follow me and I will guide you through the process step-by-step. In Unreal Engine four. 2. Introduction & Project Overview: Hello everyone and welcome to this class on Unreal Engine 4, where we're going to be building a first person shooter. My name's Tim. I'll be walking you through all the cool and awesome stuff that we're gonna do in this class. So I'm going to try to keep this first video pretty straightforward and just take a little bit of time to go over in a more detailed manner who this class is best suited for. And then when take some time to overview the final project that we're going to be building. So pretty much anybody who wants to can take this class, I do recommend it for people who are more of an intermediate level. So if you have taken the previous course that I made on action adventure games, then you should be fine stepping into this. When I say intermediate, I don't mean somebody that knows an extreme amount of things. I don't want to push people away from taking this class if they've never touch Unreal Engine before. But you just have to know that like I'm expecting you to know very basic stuff. Just not gonna be taken the time to explain what the differences between like a float and an integer going to be creating a lot of variables in this class. And I'm not going to be taken the time to overview like where things are located in the engine and what a blueprint is. And just like the very basic beginner type stuff. So if you are worried about that, you can go ahead and take the other classes that I've made. But if you feel pretty comfortable with that stuff or you just don't care, then you are in the right place. I am not going to be the type of person that's just going to be dragging out a bunch of nodes and just says Do this, do that, do that, and then boom, this thing works like I really do want people to learn and understand what it is that I'm doing. So I am going to be thorough and meticulous as best that I can so that you can understand what it is that we're actually doing so that you can create something on your own because you know, that is the point, isn't it? So hmm. Just thought I'd get that out there before we get started. But if you do have any questions, feel free to leave them in the discussion and I will do my very best to answer them as quickly as I can. So yeah. So let's go ahead and take some time. I'm going to open up the project that we have. This is going to be pretty much exactly what your project will look like when everything is all set and done. So I'm gonna go ahead and click Play and we'll see what we got here. So right away you'll notice we have some enemies over here. We have a very basic kind of minimap that trick tracks. We can see traces. Traces tracks. Who cares, where our player is moving around the map. It's nothing special, but it'll give you an idea of like how to do that type of thing. Over here we have two different types of surfaces that I'll explain why they're there in a moment. Back here we have our weapon locker. We have six different weapons are going to be making, three of which are hit scans. They're going to be drawing out in these invisible lines. It's similar to like a game like Call of Duty, where the hit of the bullet to the surface is instantaneous. And then our last three over here, the sniper rifle, grenade launcher, and rocket. Those are gonna be projectile's. We're actually going to spawn a blueprint that as a projectile that has a movement component to it, it's going to shoot out of that guns barrel and we're going to see what that hits. And so we can do cool things with that. We can apply different speeds and different gravity to create different arcs and explosions and cool stuff like that to do some radius damage. The pistol is semiautomatic. The rifle is going to have some recoil to it and be an automatic variant in the shotgun is going to shoot a spread. So if we walk up to any one of these weapons and hit the E key, we will equip it and you can see our current ammo or reserve ammo and then also the fire type. And then you see this stamina bar also show up in the bottom right. And then we have our crosshairs, which dynamically set to the player moving and sprinting. So it's all animated. I'll beautiful. So the order in which these weapons are picked up, it actually doesn't matter, but whatever order you do pick them up in, we'll sort of bind them to that key. So we picked up the pistol first. So if I hit one, we'll switch back to the pistil and I've hit two will go to the assault rifle here. Then three will be our shotgun. Fours are sniper rifle, five is our grenade launcher, and six is our rocket. And all of them have their cool little sounds and everything like that. So if I go ahead and switch back to the epistle so you can kinda see the bullet spread. Think pistol to feel like the cross hairs to rocket. Rocket doesn't have good hip fire. And hip fire is something that we're going to be doing and actually matters. I'll explain that to seconds. So over to our ammo types, we have an AML variant per each weapon. If I walk up to it and hit E, won't do anything unless you pick up the correct answer. So this is the pistol ammo. And if you look at our reserves, the 144 now becomes 16 eight. And I can't interact with any of these other ones, but I switched the assault rifle. I can pick up this one, the shotgun. This one. You get the point. Okay. Moving on to our different surface types. So a way to illustrate this in the hit scan at projectile's show you. So if I shoot this out into the sky, the epistles hit Scan. You're seeing, you're seeing some effects, but nothing's actually happening. I can go ahead and reload our gun to. But if I switch to something like the sniper rifle and I hit firewall, actually, if you look at the barrel, actually saw something come out of that. Again, it's very apparent of you used the grenade launcher. Can see a much more drastic arc there. So what we're gonna be doing is we're going to have different impact effects depending on different surfaces. So we have metal, which are mannequin men are of a metal variant because we're lacking in the FX department here. Just give a demonstration and then we have stone, so a couple of different effects. So if I were to shoot this, you notice some bullet holes go into it like that. And we're going to customize the sizes of those. And you'll see some little metal flickers. And then we have different it's a little bit hard to see with the pistol. But yeah. So if I switch to our assault rifle, couple of things we'll do with that is if I just hold down the trigger and I'm not aiming, will have some recoil That's moving the gun upward and the bullets are kind of randomly spreading. But if I were to aim in not controller recoil and actually only reload here for a second. So I can demonstrate this. I'm aiming and the bullets land exactly where it is that we're aiming. So we'll have realistic hip fire added to that, then the shotgun, if we shoot that, we will get a spread. Like that. Pretty cool. Lastly, I'll show, I think I showed the stamina bar how that goes down for running. Let go. And then it goes back up like magic. Wow. Last but not least, we have our enemies. So all of our enemies are the same. And what we're going to do is recreating hit markers. And we're going to have different types of HIT markers depending on whether it is a normal hit or a kill hit. And then we have different physical materials assigned to these enemies here. It's going to detect different amounts of damage depending on where we hit them. So the head is going to do the most. We're going to Yeah, The heads can do the most. Then we have the body, the legs, the arms. So if I were hit him in the chest, 2015512, and then the head is kinda cool because if we hit him in the head will get a yellow number like that and then he has a 100 health. So he might die here. And we should get a read hit marker like that. And then we have a rag doll physics that are applied to these. So we're going to actually shoot out a little bit of an impulse depending on where we hit them. So if I have 20, 40, 60, 80. So if I were to shoot him like in the arm, it moves back with the arm. And then different gun select that pistol doesn't have a whole lot of force, but our shock and does have a lot of force. So if I hit him here, he was flying backward. We get them in the back, wheels flying forward. So all of that is dictated by where we're hitting these enemies. Sniper rifle, we can aim in with a scope. There we go. And then last but not least, we have some grenade launcher and the rocket to impact damage. So you're going to see many damaged numbers and like a cone of it, like that to get some cool explosions, some bigger impact effects and all that. So that's pretty much the project. That's what we're going to be making. This. What I wanted to create with this was essentially like a really, really great template. So the way that we're constructing this, as you'll see, that when everything is said and done, you will have a really, really robust, advanced system of weapons and pickups and different physical materials so that you can easily swap in your own GAN meshes and your own guns sound effects if you want to be able to make it what you want. So while there is art, I guess in this class, like we do with sound effects and we do have some art. Most of what we're going to be doing is going to be using blueprints and scripting in the Event Graph. So I wanted to get all that foundational knowledge there so that if you did want to put this in your portfolio, you can make this easily into like a futuristic shooter by swapping out the meshes. The sound effects, like I said, are you can make it into survival zombie type game. You can make these guys aliens or zombie their army men or whatever. You can adjust the amount of ammo and the types of the amount of damage that they do. We're gonna make all of that very easily accessible. And the reason that I did that was because I wanted to provide a foundation, like I said, so that you can make this into the type of game that you want to make it so that everybody's project at the very end won't look like the same. So you'll all have this, but then you'll have the knowledge to very easily edit this and make it into something beautiful that you want because there are so many different types of shooters out there. So I wanted to provide that base for you. So hopefully that sounds interesting and fun, cool. And if it does, I will join you in the next video. So thank you guys for taking this class. I really do appreciate it whether you are a returner or this is your first time. In let's get started in the next video. 3. Download & Install: Hello everyone and welcome back to another Unreal Engine 4 video. This one is going to be really short, sweet. And to the point I'm going to do is just briefly talk about how you can install Unreal Engine 4 under your computer if you don't already have it. So if you open up a browser of your choice and head to Unreal Engine.com or whatever. This, I'm in the United States. So whatever it is for you, head on over here and you'll get some information about the engine in all of this cool stuff, some games that were made with it. All of that great, cool epic Games stuff that they got going on here. Just go on ahead and click on Download. You're going to want to just get the nice creators license, which is absolutely free. Hit download, and then follow the steps to do that. By doing this, you should also have the Epic Games launcher installed on your computer. So if we open that up and you have an account on it, you're going to go down to this Unreal Engine tab and then go on to the library. Then you should see here this is Engine versions that you're going to hit the Plus. And then you're going to select which one you want. The one that we're going to be using for this project is 4.26.2 or 4.26.2, I guess it's what it's technically called. Technically speaking, you can use whichever one you want. If you want to use this four-point 27, or if you want to be real crazy and do Unreal Engine five, I guess, Go ahead. I would advise you use 4.26.2 because that is what I'm going to be using. That's like the latest version that is like not an early access things. So it's going to be the most stable. And while there aren't, like typically a lot of huge differences between Unreal Engine versions. As you make this, you might run into a couple of those little types of things. You might find something that I'm doing is just a little bit different in your version. So if you want to play it safe and you want to play it smart and not take any risks, then download for 0.26.2 otherwise, best of luck to you. But once he get that done, we'll be ready. In the next video, we're going to start creating our project and adding some content files. So I will see you there. 4. Setting Up Our Project: Everyone and welcome back to another video on Unreal Engine 4. Now that we have the engine hopefully downloaded, we can start to create our projects. So that is what we are going to do in this one. Okay, So in your epic Games launcher, go ahead and click Launch next to your whatever engine version that you have. And then after a second of initializing and loading, this menu is going to open up. We're going to click on game because we'd be making games. Hit next. And we are going to be working in a blank project. And unreal does have a first-person templates. And while that's all well and good, pretty much all of the code that Epic has in there we won't use anyway. So by using a blank project, we're going to have to do a couple of steps in this video and the next one that we wouldn't normally have to do. But in doing it this way, we can have everything and more personalized the way that we want it. It's just going to work out better for us. Okay, trust me. So go ahead and click on Blank Project. Find a place on your computer that you want to save this project. And I'm going to call this FPS. What should I call it? Class project. That's looking pretty good to me. All right. And then go ahead and when you're ready, given it a name, go ahead and click on Create project. With our project open. If you did it correctly, you should see these two weird, funky looking chairs with this very expensive glass thing sitting on a table. Why this is the default engine thing. I have no idea, But it is. We can go ahead and click on this little button here to show all of our folders. The whopping, one of them, the starter content that should have been enabled automatically. And we are going to start by setting a couple of things up. So let's go ahead and right-click on content and make a new folder and we'll call this FPS. Oh, shoot. Fps game. Could like maneuver around my microphone. Hold on a sec. Okay. Underneath that folder, Let's right-click there and call this blueprints there as well. They're right. And then underneath again we're going to make another one called character. So FPS game blueprints character. And if you're like me, you like to set things as colors. So I'm going to hold down shift and select all of them. Gonna go to set color in. I'm going to make my folders red. Let's do it like that, okay? And if you were smart, unlike me, you would have dragged this and saved it appears we can always use it later. Okay, in our Blueprints folder, Let's right-click and open space. Go to Blueprint class, which is ridiculously hard for me to say for whatever reason. And we're going to make a game mode based game mode base, as it says right here, this tool tip defines the game being played, its rules scoring other facets of the game. We are not going to be putting whole bunch of data in here, but we are creating this was called BP underscored game mode base. And let's right-click. Make another class here, player controller, BP underscore player controller. And then last but not least, let's click it again. And then underneath all classes is dropdown menu. Let's search for HUD, right, should be good doing something with the HUD. So let's go BP underscore HUD. Well, we can do is we can hit the Save All button. It'll get rid of these little asterix there. So all of our things are now saved. Then inside of our character folder we're going to make our character. So once again, Blueprint Class character and we'll call this bp player. It Control-S. To just say that really quick, I do that a lot. Yeah. So two ways we can go about doing this. We can either double-click on Demode base or we can do what I like to do, which is settings, project settings. Then underneath project here there's this tab, you're saying maps and modes. You click on that. So we'll drop down under selected game mode. You see we have all these little default things that are grayed out. This is why we mainly created a game mode base so that we can slot in our character as our default upon. We don't do that, then it doesn't matter whatever scripting but near the game will not register this as the character that we want to play us. So let's slot in BP Game Mode base for Default Pawn. Let's put in bp player and our HUD class, dp HUD and player controller class bp, player controller, game state player state spectator game instance can create those if we want, but we won't really be utilizing them. So the default ones should be just fine and dandy. One other thing that I want to do before I end this video is on this little drop-down menu right here, on a right-click in advanced settings underneath play, this is just personal preference. I like to select game gets mouse control. This allows it to that whenever I hit play, I don't have to click inside of the window every single time there's automatically enters into the game. And then underneath that same drop-down, I like it a new editor window, rather than playing in this thing. So if you notice if we hit Play, you have music. Well, it's not really music. It's atmospheric sound, I suppose. And hitting the keys are hitting the mouse, moving the mouse, it doesn't do anything right now because we have not added that script yet. So if you were to do it the old-fashioned way and use one of the templates and only you can move right away. But in the blank template, you can't do that. So in the next video, we are going to allow our player to start looking around, moving around. And yeah, we'll do some lattes tough. So right now it's just some basic framework stuff, but it is good to know how to do this. So that's what we will be doing in the next video. So I hope to see you there. 5. Making Our Character Move: Hello everyone and welcome back to another video. In the last one, we created our project. And in this video we are going to allow our player to look around and move so that we're just not this weird, immovable. I do not even know what you want to call it. So to start this out, pretty simple, Let's go to Settings. Project settings already have it open here. And then underneath engine, you're going to want to select input. And you'll see these bindings for action mappings in access mappings. We want to create several of these. So let's start in, do this in a strange order because actually map he says on top, Let's click the plus sign. And let's type in jump. Underneath this. Just type in space bar. That's all we wanna do there. Underneath access mappings we want to create 41234. You have to hit this little triangle to see them. We're going to create one called a mouse X. And clicking on it might dropped on all of them like I just did for me. Mouse Y is another one I want to have move forward and move right. For move forward and move right. You want to hit this little plus to make sure that there are two of them. Mousex, mouse white and leaves one. So for mouse X, we'd want to make that mouseX pretty crazy stuff for mouse. Why? It's not mouseY, It's mouse was okay for move forward. He wanted to make it W and S. And right, you want to make it D and a. Okay? But one thing you might notice is these little scale things here. So for why we don't play inverted or not weird, we're gonna make it negative one for move forward for S, since S would be backward and we're making one for forward, we want to make that negative one. Same thing for a. A would be left is the opposite of right. So we want it to be negative one as our scale. That's all set up and willing good. So you can technically exit on out of there. The next thing that we want to do is an either blueprints you want open up our player controller. Right? You'll see this word camera. Ignore the camera, delete the default nodes there. And what we're gonna do is we're going to call upon those two mouse input. So I made, so we'll type in mouse X. You want to click the axis event. That's what we just created. And a mouse, Why not you? There we go. From mouse X, we want to add your inputs. If I can spell, there we go. And the axis value is going to be that value. Now if you wanted to change this by a variable, you could do a little multiplication here and said to a variable, change your sensitivity settings that way. That might not have made sense what I just said. But don't worry about it. It's not important. For mouse why you want to add pitch plug-in axis value to value. Let's go ahead and select the whole thing. Hit C to make a comment box and we'll just call this mouse inputs. Like that. I don't like the bubbles and I'll make it read like we did before. There we go. And that's all we want to do. Next to compile this drop-down, go ahead and hit Save on compile and do on success only. That means that whenever you hit Compile it will also save. Hey, compile, save a reasonably good to know these little things. Trust me, people. Like Control S right there. Next up is our HUD. We're going to head over to the Event Graph in here. And we're gonna do event drawn receive HUD. See what this does in a second. Out of the execution wire you want to do draw a rectangle, draw rect or whatever. And then out of size x, plot an asterisk, do multiplication for an int or a float. And then copy paste it and do it for size. Why? You want to plug this in for screen x size x green x size. Why screen? Why? We're going to multiply this by 0.5. What we're doing here is we're drawing a little rectangle on our screen. Said that color and make it white. And we'll make it two by two, W and HR width and height. So not pretty straightforward there. 0.5 is she taking the size of the screen in the x and the y and it's cutting in half. So just to demonstrate this, if I hit Play, you'll now see I can move it. I can look around for one thing and you'll see a little dot there that's going to be helpful for us when we make our radical. You can see the center of the screen. So the controller and the wheter, all good. The last thing that we wanna do is we want to allow our player to move with W, a, S, and D. And we want it to be able to jump. So let's open up our player. I think all these settings actually go ahead and use controller rotation. Yeah, uncheck that with the VP. Play yourself. Undo that. Actually, I'm going to make a new event graph and I'm going to call it and movements. If you wanted to add a new event graph, you just hit this little plus on new graph. The reason I'm doing that is just for organizational purposes, I want to put all of my sort of movement components, jumping, sprinting, moving in one event graphs so that there's just not like one conglomerate of events all in one graph. I like to stay organized. It's important. So right-click and we're now going to call move forward, not the function, but the axis event that we created. And as you can probably guess, we wanted the same thing for move, right? Okay. Out of move 40, want to add a movement input. And we want to do the same thing at copy paste that from move right in the axis values and the skill value just like before. But out of World direction, we want to get the forward, forward, forward. Why? Well, I spelled that wrong. Most of the forward vector for forward and then World direction out of right. I'm going to get the right vector. Drawing out of any one of these rotators. You want to make a rotator. This bottom one right here, actually plugged it into both. And I'm not going to go over in detail what the heck is happening right here, because this is what's normally set up by default. So it's really not that crazy. What we're doing here. We're just kind of setting up like if you made like a third-person project or first-person project, this script is already in here by default. So out of maker rotator and drag out of anywhere in se break the rotator a WHO, the old law control on any node and click you can actually grab it and plug it into some other ones. So we want the xi's to be connected. And out of this rotation, we want to get control rotation. We're getting rotation of our controller there. I believe that is correct. So let's highlight the whole thing. Hit C and it'll say WASD movement. There we go. That last but not least, let's do our thing for the jump. So we have action event jump. So what we want on pressed, these are already built-in, so epic makes it very nice and easy for us. Press you wanted to jump in, then released is stop jumping. And then let's comment box around that. And we'll say action, event or whatever. Sure. Whatever you want to call it, whatever makes it easy, whatever floats your boat, let's say Compile and Save. And so now when we hit play, we can look around. You can move forward, backward, right, left, and we can jump up and down. So now we are a character that can move and stuff. Okay, so here's the script. If you need to see it again, just pause or do whatever you need to do. There it is. But yeah, that should be it. So in the next video, we have our character setup. We're going to start adding some content packs. And then once we do that, we will start actually doing some cool stuff like adding the guns and creating our character and give them arms and stuff like that. So hopefully you guys are looking forward to that and I will see you in the next video. 6. Adding Content Packs: Hello everyone, Welcome back to another video. In the last one, we set up some character movements and very basic stuff. And in this one we're going to start adding our content packs to the game. There is only one, or technically, I suppose, whichever way you look at it. So let's go ahead and add into the Epic Game Store under the Unreal Engine. And let's move from our library tab over to the marketplace. Done. Okay? And then enter search products. You want to type in military weapons. Silver should see this. Military weapons silver pack. I believe this particular maker has a couple futuristic ones. And like a military weapon, black or like a different kind. But the silver is the one that has the necessary weapons that were going to be using. You can feel free to use some different ones, but just know. You gotta use them at your own risk. If you want to stay true to knowing what works, I will just use this. But, you know, you can do whatever you want. It's up to you. So in this military weapons silver packet we're gonna do is we're going to add to your project. And you'll notice that it doesn't say there's any compatible ones. Rest assured, we will work around the Soviet. You click on this and able to call it a button. And you'll show all projects. Go ahead and navigate to our FPS class project or whatever you named it. And it'll say that it's not compatible with 4.26. But it is, I assure you, because technically you saw in the demonstration that it was. So let's go ahead and select on for point 2 1, which is the last engine version that it was compatible with. The Engine versions don't change that much to the point where it will really screw up the weapons, they still work. And 4.26, even though they're like, like not technically compatible or whatever. So go ahead and select that and then add two project. And if you look over here, it will add it to the project and it worked just fine. So that works. The other thing we wanna do is head over to the Learn tab, which I honestly did not know existed until after like a year of using Unreal. And the Learn tab has a whole bunch of these really cool demos and different games like an RPG and vehicle game and some, some art landscapes and just some cool stuff here. You're going to want to select on a shooter game right here. Now this one can not be added to a project. It is its own file, so you will need to create a project and installed somewhere on your computer. Rest assured, whenever we're done with this video, you delete it. We only need a couple of folders from there, so go ahead and create that project. Now I went ahead and took the liberty of actually opening this project up. This is not something that you have to do by any means, but this is a pretty cool project to look around and have some fun. And we're going to be using some of the assets from here, but not all of them. So a couple of different things that you can do at this point. If you click on content, right-click and say show in Explorer, you your Windows Explorer. I don't want to call Internet Explorer. I don't even know what a hectare your folders. Okay, we'll open up in this content browser and you'll see how these folders correlate with these folders. And that's what we want. You can do it that way. Or in the Epic Games Launcher, you'll see shooter game will show up under my projects. You right-click on that. You can show, showing the folder that way. And then you just click underneath content and then it's the same exact thing. What we wanna do is we want to grab animations, hold down control characters, affects Ozone, sounds. Right-click and hit Copy. Now if these are, if these both these projects, The Shooter game and the one that we created are in the same folder like they are for me, which is here. You can go ahead and just go underneath content and just paste them right there. But if you have an issue finding where that is, you just go to your project. Same thing, content, show in Explorer and there it is. And then I'm going to right-click and hit paste. And you'll see how they're showing up right there. Now this might take a little bit of a second, but I'm going to actually make a new folder. And we're going to call this shooter game. And I want to take those animations, characters, effects, and sounds probably should have done this the other way around. But here we are going to drag this into shooter game. That might take a bit of a second to do. Oh, did instantaneously. If you do that within the engine, it'll probably take a second if you do it in the File Explorer, it's like bam, instant. The only reason I did that is just so these things are nice and organized. You might notice that these are the Cray copies. That might, that'll probably go. And quite honestly, because if I go and read the content, see how it's not there. So this product needs to be refreshed. If a poses down, open it back up, it'll be fine. Okay, so that's all we wanted to do in this video. We've added our content packs. I'll actually the last thing we need to do go to Add Import, go to Add feature content pack. And then we're going to need to grab the third person, a blueprint feature because we need the mannequin man. Literally the only thing that we need. Adding this one might screw with our input mappings a little bit, but we can always just close them down. We'll have to see. So let's just add this to the project. And then there that shows up. Please tell me this still works. It does help. Thank goodness gracious. Because I think if you go into it, might've added, yeah, so it added some of their other inputs, which is not what we see is get rid of them. Yeah, and all works. It's all good. So that's gonna do it for this video. Thank you for watching, and I'll see you in the next one. 7. Creating the First Person Character: Hello everyone and welcome back to another video. In this one, we are going to be continuing on and we will be setting up our first-person character. So if you have our project open, go ahead and under FPS game character, Let's open up the blueprint of bp player. Drag it across the top if it already isn't. And we're going to be messing around in the viewport. So with our character selected, we're going to add a components and we're going to add a camera. And we can just keep this with the name camera. Then underneath camera with its selected, we're going to create a child on that camera. And we want to slot in a skeletal mesh. And we can call this player arms. Okay, So with cameras selected, there's a couple of things that we want to do. We want to check Use Pawn Control rotation. That is one thing that we want to do. Sorry, I'm just referring to my notes to make sure that I'm not missing anything. I think it's actually 0 for the camera on the Z, we want to set that to 75. So location z, 75. Then on the player arms, the skeletal mesh that we're going to slot in is this hero F PP right here. It's going to spawn in up there. Now what we can do with this little magnifying glass, it'll open up where this asset is within our content browser here. And what we can do is we can drag this and then drag that into our character folder so that we can see it here. And then we can hit F2 and we can rename it player arms. So it's the same asset. But now it's an R folder and we can access things with it. So with our player ARM selected, one thing that we want to do really quickly is search bounds scale. We want to change this to two. The reason we're changing this to two instead of one is that if you don't change it to two, it's going to interact with the camera funny. And depending on where you're looking, if you're looking straight up or straight down, the mesh will actually disappear. So that's just a little weird setting that you want to make sure that you do. So for the arms, the location, I'm just going to give you these numbers so you have to fiddle with it yourself. I already graded all this for you. X is going to be negative ten, z is going to be negative 1, 50. And then the z rotation is going to be negative 90. So facing, turned on my camera speed a little bit, it's facing forward. You got the arms like right on the camera like that. That looks pretty good. The last thing we want to do with the arms is make sure that we don't have a shadow because we don't have a whole body. So it will hop in and play and show you this. It looks little freaky and we don't want freaky. So let's just uncheck cast shadow underneath the lighting again with player ARM selected compile. And then there we go. We look normal. We can't see the arms right now. Okay. A couple other things I want to do in this video before we move forward underneath the Character Movement Component, this is just my personal preference here. Let me find it. Max walk speed is at 600. I'm going to set that to be 750. Like the character walks a little bit slow by default. And I think that's it. So if you'll notice the material that is on these arms coming out screwed up by transferring it over. So what we're gonna do is we're going to remake it. We're going to make it exactly how it was originally. So Let's right-click on FPS games select new folder and we'll create a new folder called materials. And I'm going to set that to our red color, whatever color that you have. And then over here, you're going to right-click and go to materials and textures are going to just go material right there. We're going to go M for material underscore layer farms already. And then we're going to open up player arms. Believe you can do this. Nice. Okay, so if you hold down T and click, you can get texture samples. And for this texture sample, what I wanna do is we want to plug one into Base Color 1 into metallic. And it's going to be errors, but don't worry. And then the other one into normal. With that setup, you're going to right click and you're going to search a constant. It's going to be just this little thing with a little number in there. And we're going to put this into roughness. And since I'm a perfectionist, we're going to make sure that all of these are in order like that. For our roughness value, we're just going to make it something like 0.3 or something like that. And then for this texture samples, so we have some textures that exist. Within this previous project, the shooter game is where we're pulling these materials from. So this material, if we open this up, It's all kinds of screwed up in here. As you could probably see. That's what we're trying to recreate. So we're going to have to use some of these textures that exist, these ones that still function. We're going to use those. So that sap one that we want is you can just do FPS underscore d in FPS underscore M for the metallic. And then for our normal, you can probably guess it's going to be FPS underscore N for normal, then you should get a preview to show up. So this roughness of it actually says, so it doesn't. So if I set this one, you can see how there's like no super rough, no shine whatsoever. Said zeros can be really glossy. So I live around the 0.3 range if you want to make a point or maybe you like it real shiny and just wanted to 0.1.2. That's fine too. I'll stick with 0.2. So there's our material. You can click Apply. That's all we're gonna be doing there in save it. And then we're going to apply that. So it's called player arms. And there we go. So it fits perfectly. Prepare the last thing that we wanna do in our character folder. So we're going to right-click and we're going to go to Animation, Animation Blueprint. So in animation, blueprint is a blueprint that can connect to Skeletal Mesh and it will control essentially what animations you want to play one. So we're just gonna go ahead and do this right away in actually. Before we do this, let's do one other thing. So before I mentioned I like copy these arms. I want to make a new skeleton. So I'm actually going to take this hero FTP skeleton and copy paste that. So we can find that we go into shooter game characters here, FTP in this skeleton. So let's go ahead and move that into our character folder. And then we'll name it like player, player skeleton. Why not? So it should be kinda messed up right now. Hopefully it's still able to work. One thing that we can do to check and see if it does work as we click on one of our animations. And then let's do one where they're actually going to use. So rifle idle is one of them that we're actually going to use. So it's going to be like cannot find skeleton, would you like to choose a new one? So I'll say yes. And we'd have right there player skeleton and it'll retarget it to that skeleton. And it aids us and doesn't want to work. Devil of copy and pasting, ruining assets. Okay. Give me a second. I'll figure this out. That Lubeck. Okay, so I think I remembered how I did this before. So if you click, double-click on our skeletal mesh is actually going to prompt you to ask you to create a new skeleton, and that is what we want to do. So it's going to have all this stuff already pre-set up in here. And it's going to essentially assign this mesh to this skeleton, which as we want. And so it named it player arms skeleton. So I'm actually going to delete this. Hopefully the computer does not hate me for doing that and forced deleting it. We're good. Let's give it a name list player underscores skeleton. And then now if we were to go back into our shooter game animations, and we would do something like rifle equip. And it would say cannot find skeleton. Would you like to choose new? And I'll say Yeah. And then we'll choose our player skeleton. And the animation works just fine. So eight, so now we have 12. So we just have to manually, when at whichever animation of these that we want to use, we'll just have to manually click on it, add it to the skeleton, and so it'll show up over here in our asset browser. So we can do that for rifle idle. I'm just going to do that because that is going to be our main animation right there. Pretty good. Okay, So back in the character, we can now create what we wanted to create in the first place, which is Blueprint. No animation, animation blueprint. And then we'll put this on our player skeleton, the one that we just created. And we'll call this player underscore Anim VP. And we don't need to actually do anything in here right now. What we're gonna do is we're just going to assign it, use animation blueprint with the arms selected. And we want player in and BP. So it's not actually going to do anything right now. But now that is, functionality is now wired up in our character folder. So that is all I have for this video. I believe. I don't think there's anything else that I left out. Just check in the notes and it looks like we're good. So that's gonna do it for this video. In the next one, we're going to continue on and start animating our character. So he's already from we start putting guns in the hands. So I will see you there. 8. Animating Our Character: Hey everyone, welcome back to another episode in our Unreal Engine 4 series, making a first-person shooter. In the last video, we started creating our character. We gave him some arms, created a material for that. And this one to prevent him from just standing there awkwardly in the oppose all the time. We're going to be doing some work in this animation blueprint to give him some movement. Okay, so the first thing that I wanna do is open up our player in MBP. And if you haven't worked in an animation blueprint before, essentially a Animation Blueprint is a blueprint that links up with a certain skeleton and part of a certain character. So if I were to go on my skeletal mesh, on my players arms, which are these things. You can see that the mesh or the animation has an animation blueprint associated with it. And it is this one that we created in the last video. So whatever we do in here will be outputted here and our character. So anything that we plug into this output pose is going to be outputted to our character. Animation. Blueprint has an animation graph and an Event Graph. The event graph is essentially just a graph that links variables that will create two variables found within this blueprint. That'll make more sense when we actually do it. And then the animation graph is where we actually implement the rules that will decide which animations to play when. That's kind of the best way I can explain it right now. But it'll make more sense when we actually start putting some stuff in here. So what we wanna do first is we want to create an animation blend space. So with our character folder open, Let's right-click in empty space and go to animation and blend space, not displace 1D. And we're going to use our player skeleton, which is right here, the one that we created. And let's call this Idle run. So I don't run is a very common type of blend space. Blend spaces allow you to place multiple animations within them. And then you can change a surgery which animation you're playing based on a certain axis value. So in this case, our name is going to be speed. And what we're gonna be doing in this blend space is we're going to be transitioning from an idle pose to a walking pose. And that is going to be dictated by our speed. For grid divisions are okay, or maximum axis value, we're going to make 600. If you remember in the last video, we set our character movement to 750. So if we are going 600 and above, I want to switch between two different animations. So rifle idle is the first one that we want to grab. And we're going to drag this at 0 right here. This green dial is what we can see to kind of move between. You can see the speed value changing right there in the preview value right there. And we're going to need to grab another animation because these weren't default. We'll create a new skeleton in the last video. So it's going to shoot a game animations, first-person player animations right here. And you want to do not erode your rifle? Or should this be like our rifled? Run him a quip fire. Am I blind here it is. Ftp or rifled run. Double-click on that. Could not find skeleton. So we're going to assign it to our player skeleton and a retarget. And you can see there it is moving there ahead and hit Save. We can pause it. We can mess with the sounds of that later. Okay. And I think I exit out of our blend space. It's awkward. So I'm going to open that back on up. Then I'm going to take our rifle random and drag that at 600. So now you can see if our speeds increasing, you can see that animation changing from the idle 1 to the running one or the walking one and whatever you wanna call it. So we're going to hit Save. That is looking good. And now let's go into our animation. Blueprint, event blueprint of DNA. Okay? So in some empty space in the event graph, we're going to search for an event, events. Blue prints initialize animation. This is the equivalent of an event begin play. For animation Blueprints. What we wanna do is right-click and say, Get Owning actor. Sometimes you say get player character, Get Player Pawn. Sometimes it doesn't matter. But we're going to cast to rbp. Not be 0. Bp player. Whatever the object is, it just sometimes just further. This is the only time we're not really going to be using casting or getting the character. Let's right-click on bp player and promote this to a variable and we'll call this player. So all this did was we created a reference, reference to player. So that now what we can do is we can pull this out. You can get it. And then any sort of variable that is found within here or function or whatever we can just pull out of there. So creating references to things is something that we're going to be doing a lot will mainly be creating references to our player. Okay, so now down here, event Blueprint update animation. I'm going to call out a sequence node. Not actually going to be doing anything out of the sequence just yet. But just for future reference out of then one will say is valid with the question mark. And plug that into try, Get Pawn Owner. And is valid node is essentially just a way to it's kind of given the computer common sense. So if if something I actually don't even know how to explain it, but it's saying like, it'll make sense, we'll be using this in the next video as well. And I'll explain it in more detail there because it'll be a lot easier to explain kinda what it does there. Okay, now, let's head on over to our Anim graph. And we're going to right-click and we're going to look up a add a new state machine. And I want to click on this and rename this. And we'll call this player movement and will for the time being, let's just put this right into the output pose directly. If you double-click on a state machine, you'll see this entry bubble. And what you can do is drag out and you can add States. We're not going to be maximum then a conduit states or whatever. So let's drag out and let's add a state and we'll call this Idle run. So if you're unfamiliar with state machines, these states are where you will plug your animations in and then you can create transitions from sub I added a different state. These things essentially are conditions that need to be true or false to transition between different animations. Like I said, a lot of this stuff makes sense like when you're actually doing it. So let's double-click on Idle run. And what we wanna do is we want to grab our blend space named Idle run and plug that into the output pose. And what you'll notice with this one is that it has a speed variable. So if we were to do this, but see we have our name for speed. So that's what it's grabbing right here. So right now it's set to 0. And we don't want that always be set as 0 because if it's always set at 0, and we will always be right there. So we want to link this up to our characters speed. So let's right-click here promotes to a variable and we'll just call that speed. And that's all that we need to do in there. So now if we go back to the Event Graph out of try Get Pawn Owner, we're going to get velocity, the velocity of our character. And we want to get vector length. And then we want to take our speed and set that. We want the SEC amount of that is valid branch. So what this is doing right here, this first part is it's getting the velocity of our character, getting the length of that vector. And then setting that to this variable that we created called speed, which is setup in here to control which animations that we're running. So for this common box, I'm just going to say sets, walking into idle animation, something like that. So it should look like this. And then that labor movement I'll run, we only have one state right now doing that. So have you compile, we have him in idle. And if you hit Play, you can see that we have some arms here. Actually, we don't have a lot of real estate, so temporarily I'm just going to fill down Alt, make oh gosh it and that way I think set to ten. Hold on. Alternate. Make a copy of something, just give myself some room to walk. Now if I hit Play. So you can see I'm now idle. And then when I move him doing the walking animation, we're not actually holding any sort of weapons, so it's a little bit hard to see. But that is how that works. Probably gonna redo this environment and between videos. The last thing that we can do here is that if you actually go here and go to rifle Run, you'll see that we have these little notifies. And you can right-click anywhere and add a notify inside of an animation and play like a particle effect or a sound or anything. These sounds are actually kind of busted here, so it's placed down, it's not actually implemented. So like we can, but whatever sound that we want in here. And then whenever this animation plays in crosses over there, it'll actually play whatever sound that we slot in there. So I believe that because we got the sounds over here that we have footstep sounds, grass, metal tile, and I think that they're kind of busted up like that. So man, grass, mental tile and we got fully run. Okay. So okay, so copy-pasting the stuff over, kind of screw this up. So what we'll do here, so just follow where I am. Shooter game sounds right here. Fully run. Open this up and we're just going to slot these things in near the sound wave. So we got fully run one through 10. So one. I'll give you a second to do this and then come back. Okay, Now that all of our run waves are now properly put back into this randomizer and outputted. This sound cue should actually work. So inside of our rifle run animation, play sound, and then we go to sound cue. See you actually hear it. I'm gonna make the volume of the player one. I wanted to be a little bit lower. And then we'll do the same thing right here. Set to one. It save. So now I got rid of my lord. What am I doing? So now whenever we walk, you should hear some footsteps. And I fall right off the map, but you can kind of see it has that ambient sound. Hear me actually get rid of that senior. That sounds much better. Footsteps, better soundscapes come up to him. Okay. And if you don't feel like that's in the right spot, you can move these around to different locations and preview it in here. Like that. But yeah, that's, that's how we can add just basic walking into our game. So in the next video, we're going to continue on and actually start putting some weapons in these hands. So I hope to see you there. 9. Equipping Our Loadout (Part 1): Hey everyone and welcome back to another video. In the last one, we set up some basic player movement, getting our character to look like they are walking in between videos, I did a couple of things. I went over to geometry. I drag a box in here so that we have a little bit more room here. If you're curious what I did. I set x to 2500, y to 2500, and z to 100. And if you go into our orthographic view, I made it nice and centered here. If you have things that are off of the grid. So like I have my snap settings to on 100. So like if I were to just kinda like move this over here, a 100, see how it's not in the grid. If you have that issue, just hit Control and it will then snap to whatever grid size that you're using. If I can undo that some of the rebuild anything, okay. That's what I did. And then if you have like your player equals like a bad size or he's just like up in the air. If you hit the End key, end is next to delete, by the way, hill then hit the ground. So Control N snaps it to the grid, whatever grid settings. And but something like on the ground. Fun facts to know about Unreal Engine. Okay, so now with that done, we're going to continue on. I would also make sure to name your things. I named this floor and put it into folders. Organize your life. You will thank me later. So in this video, what we're gonna do is we're going to start writing the code that's going to allow us to put weapons in our player's hands. Immediately. This is going to be one of the most complicated scripts in the game. In the game. I guess I really actually made sense in the class. That's what I meant to say. It's not, you know, it's not super complicated issues very long. And the flow of consciousness of this home, There's a lot of nodes since we have six weapons, There's a lot of copy pasting. So it can be easy to get lost or, you know, just kinda get confused like where all the data's getting pulled from, you'll see. But I'm gonna try to walk you through it step-by-step so you don't get super confused. Okay, first thing that we wanna do is you're going to right-click on FPS game, create a new folder, and I'll call this data right-click and FPS gaming and create a new folder. And I'll call this weapons. I'm going to set both of those two are nice red color. Instead of our data folder, what you wanna do is we're gonna create an enumeration. Right-click, go to Blueprint. Enumeration. And enumeration is a list of named values. It's really not more complicated than that. It's just think of it like a list. So yo E underscore, load out. So we're going to name this one. You double-click and open that up. We're going to create to enumerate tours 12. And then we're going to call one no weapon. And then this other one has weapon. Save it. Close. It is beautiful. So I could write to click again, make another one enumeration, we'll call this E underscore and a weapon type. Open that one. We're gonna have six integrators here. So 3, 4, 5, 6. And if you're really, really smart, you'll probably know we have six weapons, so we're going to slot the names and of our weapons. I'm going to call a serif auto or iPhone because it's easier for me to type couple less letters. And I play a lot of destiny. So that's why I've named it that what we got sniper rifle. We've got oh, my gosh, a grenade launcher. And then Wrong kid launcher. My fingers hit wrong keys all the time. Say, cool. Now what we wanna do? If you don't already go to your character folder, open up your player, and we're going to create our very first variable. So click on variable and we're going to call this load out. And we're going to set this to be of type load out. So now if you look, we have the enumeration that we just created right there, set to a variable and liquid, we have both our options here. So we can do is like we can drag this out and we can do what's known as switched on. So now we can run different events depending on whatever that integration is set S at any given time. That's how animations work. All right. What we're gonna do now is we're going to create our very first weapon. Now, the way we're doing this is we're going to have one weapon base as the parent. Or pretty much all of our script is going to, our general script is going to lie. And then we're going to create six children blueprints that are going to inherits all of the data from the parent, the base, with some slight tweaks and deviations to it. So. We're gonna go ahead and create the base. So let's right-click and go to blueprint. And we're going to use an actor, which is an object that can be Plays respond to the world that does not receive any sort of input or anything. And we'll call this weapon. I was gonna make a joke there, but I've decided against it. Okay, on our weapon base, Let's add a components and we want to add a gel, my gosh, a skeletal mesh, and we'll call this weapon mesh. We're not going to slot it as anything. The only thing we wanna do with this mesh is makes sure doesn't cast a shadow. Because our hands-on casts a shadow. We don't want the gun in our hands to cast a shadow. And we're not setting it to anything because this is just the base. So you don't need to. The next thing we wanna do is run a create two variables. The first one is going to be of type weapon called weapon type, sorry. And we're gonna make it of type, weapon type. So you see right here I've got all of our weapons. The other one we're gonna do is going to be called sockets name. And we're going to make this of type name. The default value for this is going to be b, lowercase b underscore. Is it right weapon? Beliefs. So, right weapon. You don't have to actually do this. Well, you have to type this NB, don't have to do it. I'm going to show you right here. So if you go to our skeletal, Skeletal Mesh on our player arms, there is a socket here called B, right weapon. So this is essentially, we're going to create different sockets for different weapons because they're all different sizes. And so we want the socket to be a little bit different so we don't have issues with the gun clipping through the hand that much. But the default value is going to be this right weapon. And we're setting that to be a name because that's the socket that we are going to eventually code too, gets our weapons to attach to. And this is, since this is a variable, we can dynamically set it depending on whichever weapon that we have. Okay, the next thing that we wanna do is in our player is some open space and our Event Graph is where we're going to be putting all of our events. We're going to create a custom events and we'll call this pick up. Now if you know anything about custom events, you know that you need to write a script that actually calls that event. This event is going to be called within our, if you remember in the first video. And we had the weapons floating up and down, we're going to call this event in those blueprints. So this is just a custom event sitting here for now. Little sneak preview for the future. I suppose we're going to add an input of a new parameter. And we're going to call this weapon spawn. And we're going to make this of type weapon base. And we're gonna make this a class reference. In this course, we're going to be using both class references and object references. The main difference between them is that a class reference is going to refer to the entire class. So it will refer to Weapon Base, this blueprint, and it'll also refer to all of its children. Everything. An object reference is an instance object of type. So that would be referring to like the assault rifle specifically, are the pistol specifically, we want refer to all of the classes. So we're going to get a class reference. And that's actually all that we want to do right now. Um, because we're gonna plug a function into this. So let's go ahead and create that function. And we'll call this spawn weapons. And we want this to have an input is well of type weapon base and we'll call this weapon. The reason that we want this to have an input is if we go back to our event graph and we call this event spawn weapon, what do you know it's asking for a weapon? Because we made this input. If I go ahead and delete this input and it Compile and Save. It's gone. And we got no, yeah, nothing to plug this into. You end up in a plug this data into. And that's depressing. So we want to create an input to pass the data along through like such. And that's beautiful. I think it's beautiful. Now this script is going to be extremely stupidly long. And to prevent us from dragging out of this node literally like 20 times, I'm going to promote this to a variable. And I'm gonna put this to a local variable. The difference between a variable and a local variable if you're unfamiliar, is that a local variable is a variable that it's mainly done just to keep things a little bit more organized. A local variable. For one thing, they can only be created within functions. So if I go anywhere else, I can't create a local variable in my Event Graph can only exist within functions, and they only exist within this specific function. So I know that I'm not going to use this variable anywhere else in my script. So might as well make it a local variable so that if I go anywhere else, I don't have to see it because I don't need it. The next variable that we create is going to be used within other events. So we're gonna make it a normal variable. And we'll call this is first slot filled. And anything that starts with an a is and the question mark is typically a Boolean. So let's go ahead and drag that Boolean out. Now, what you can do is you can plug this into a branch and do the true-false thing I like to do is say not. So it saying is the first slot and not filled in, then we can plot our branch and plug that in like that. So without the knot is essentially just switches what true and false would be. So is the first slot. If the first slot is not already filled, you want to spawn an actor from class. What class do we want that to be? Well, what we can do, we have three options. We can plug in our class. From here. From here, we created a local variable, so might as well, all those three things mean the same exact thing. And this data, this variable, is the same thing as this variable, and it all equals this blueprint. So we want to spawn something from a weapon base. The spawn transform. We want to get actor transform. The actor being self. Self the player. To do, to do that over a little bit. Okay? And then what we wanna do is this return value now turned into from a class reference to an object reference. Let's right-click promote to a variable. And we're going to call this weapon slot 0, 1, like such. And then we wanna take R is weapon is first slot filled and we're going to say true it is filled. This will prevent this script running through this branch more than once. Next thing we wanna do is we want to attach actor to component. The thing that we want to the target that we wanted to attach his weapons Slot 1, whatever weapons in weapons slot one. The parent is going to be the arms. So we want to attach this actor weapon Slot 1, 2 our arms. And it's gonna be like, well, what's socket Do you want? Well, I already told you it's that right weapon. That's why we have this variable. So since this return value and this is all of weapon base, we can access its variables. So let's say get socket name and plug that in for the name. So that's why we created this variable. And we can access. I hate it when it does that, when it's not a perfectly lined up. Okay? So we can access this variable because this return value is you can see Weapon Base. So we have the weapon base, so you get its variables. And that beautiful. Now we want to create another variable and we'll call this current weapon. The current weapon is going to be a variable of type weapon base object is going to be one specific one. We're going to set weapons slot one to the current weapon. The current weapon is essentially just whatever weapon is in our hands. So if we have weapons slot one currently equipped, weapon slot one is the current weapon. We switch to the secondary weapon. Weapon slot t2 will be the current weapon. And then what we wanna do is we want to add a return note. So you want to return this data. So we can just grab this and add it right there. And now it adds a weapon base object type there. We could have just hit new parameter and then that way, but we're fancy. Name that return weapon. It's now be a compile. Let me go back here. Now we're returning data. So this data starts out over here. It's going in through here and it's running through all of this. And then it is outputting right there. And it's all type weapon base. That's how that works. But we have more than just one weapon. We do. We have six. So this is where it gets a little bit ridiculous. Out of the false branch. You then want to ask if weapons slot t2 is not filled. So let's copy and paste this. And then let's create new variable. Actually, I was going to hit Control W on this one. And we'll say is second, I should honestly name them like this. Quantum. Make it easier on the eyes is first. Slot filled. I'm going to drag second slot and pop it on there. So now if the first slot is filled and it's going to be like, Well is the second slot filled? And then it's going to run through this same line of code again. If the second slot is not filled, well then we're going to spawn an actor. We're going to put it in our hands. And we're going to set that to be weapon slot 2. And then we're gonna say is the weapons is second slot film. Yes, it is. We're going to have to do this one through six. So I'm going to skip ahead. I'm gonna do third slot, fourth, fifth. You get the point all the way through six. Then I'll come back and show you. Okay, So if you are finished, hopefully that little test, a little task wasn't too difficult. If it wasn't going to show you exactly what should be. So first slot, first slot, weapon, slot 1, second slot, second slot, seconds lot weapons like 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6. So that's this huge conglomeration of a, of a function here. What we'll do is we'll comment boxes around this thing will say spawns, weapon, actor in player's hands, and assigns can even see it in slot 0. I think I actually spell everything right there. Okay, So that's what this is doing essentially. And we're returning that value every single time. So this is how we are going to spawn our weapons. So if we go back to our event graph, what we want to do here after this is we want to make another custom event. So customers come work with me. Oh my gosh. Why can't I do things? Okay. We're going to make one called equip weapon like that. And then we're going to call equipped weapon like that. On equip weapon, we're going to make an inputs of called weapon and we're gonna make it of weapon base object. So now we can plug those in like that. So for the time being, I'm going to cut this video off here. There's going to be a two parter because like I said, it's pretty complicated. This of when this event runs, which we don't have any whom that happens here that runs it. We're going to spawn a certain weapon. So if our first slot, let's just say it's the effort. We don't have any weapons. If the first slot is not filled, we're going to spawn an actor of type weapon base. We're going to assign that to the first slot. I'm going to set that. I'm going to say our first slots now film so that if we interact with another weapon, it's gonna go down here. And then down there, down there, they're down there. We're going to attach this actor, this weapon to our players arms at that socket name. We're going to set that as our current weapon. And then we're going to return that value to then do more stuff to actually equip that weapon. Because what we need to do is we need to actually run some of those weapons switching animations in the sounds. And we need to actually have the weapon mesh appear in our hands. There's nothing that's actually making the mesh appear. And then also when we switch making that other mesh disappear. So that's what we're going to do in the next video. And I hope to see you there. 10. Equipping Our Loadout (Part 2): Everyone, welcome back to another video. And the last one, we started this very long script that's going to allow us to equip, show and switch between our weapons. Like I said, this class is a lot of event graph stuff. This is one of the heavier ones. Once we're done with this part, we're going to work on creating our weapons. And there'll be more exciting stuff going on, but we gotta get all this back-end stuff done first so that our game actually functions. Okay? So where we left off, we have our weapon pickup are spawn weapon function and then our equip weapon event. What we're gonna do is we're going to start building off of this equip weapon event. The first thing that we wanna do is we want to pull out a branch 0, also little tidbit in between videos. I took all of our variables of the weapon slots and I created a category. So all you gotta do to create a category is have a variable selected and type in a category. And then I'll create one. And then you can drag them around, put them in correct order. So now you don't have to have this super long list of variables everywhere, makes it easier on your life. But what we're gonna do is we're gonna create a new variable. Recall is switching weapon. And this is going to be a Boolean. So you want to check before we can equip a weapon, we want to make sure that we are not already switching weapons. Okay? If we are not currently, if we're not already switching a weapon, then we want to make another check. And we'll say is reloading. This is a Boolean, yes. Okay. We're going to see if we are reloading and I reloading script doesn't exist this yet, but it will eventually. This part of it is essentially here. So that if we are reloading a weapon and we try to switch, that reload will actually cancel. It won't continue through while the other weapon mesh and data appears. So if we are reloading, we want to turn reloading off. If we aren't reloading, then we just want to say, Well, we are switching a weapon. And we want to connect these two like that. If we are reloading, now we're not reloading, and then we can start switching the weapon. If we aren't reloading, then it'll just say that we are switching a weapon. Well, we wanna do here is we want to create another function to run. This function is going to exist to show our weapon meshes or and hide the one that we currently have equipped. So we will accurately name this hide and show weapon mesh. We can go ahead and close that down. We can go ahead and drag this out and put it right there. Even though there's no script in it. The first thing that we wanna do when it comes to hide and show weapon mesh is, well, we want to pass in that data from before. So we have are automatically set it to Weapon Base object and we'll just name this weapon. All right, and just like before, I want to promote this to a local variable because this is going to be a hairy, hairy function. Local current weapon. Now if you remember, I talked about is valid before and that's where this is going to come back. So if we get our weapon slots, Let's get a weapon slot, one of the first one that we want to ask, open slot 1. If weapons thought one is valid, we want to set, this might not even show up unless I have, oh, it does set actor hidden in game. The actor that we want to set hint and game is weapon slot 1, and we want to make it hidden. So true means invisible. That means visible. The reason that this is valid thing exists, okay. When it comes to this script, is that if you run hide and show weapon mesh, when weapon slot one doesn't exist, it will get confused. So is valid is kind of like common sense for computers. So it'll recognize like, okay, you're saying to make weapons slot one invisible but I don't I don't see anything in weapons Slot 1. There's no data in this variable currently. So I'm just going to carry on my way. All right, so now we want to ask that again for weapons slot 2, 3, 4, 5, and 6. The same exact thing. So we can copy and paste. Not valid. So if it isn't valid, then is going to ask about weapons slot two. If it is valid, it's going to set that actor hidden game and then it's just going to continue on the script like that. So this is what it should look like. And then we want to put weapon slot 2 in like that. So this is valid thing mainly exist because we're going to want to make weapons thought one visible, right? But it's going to continue one and it's going to look at weapons lot to the first weapon that we pick up. When we pick up our first weapon, there won't be anything in slots 23456. So is valid is going to be able to determine that this isn't even bowed. So it's just it's just a way to prevent errors. That was like a very long way of explaining that, I guess. So let's copy and paste these two and do the same exact things until we have six of them. Can hit a little reroute nodes to make it not ugly. So we got 1, 2, 3, 4, at least need two more for 5 and 6. Like I said, this isn't super complicated, it's just long because you have to check for you now, I'm being nice. I'm giving you guys six weapons over here. Okay. So we've got weapons out. One weapon slat too. Well, it's not three. Open slot for Cinco says, oh, cool. Okay, what this is doing? Let's come back from this whole thing. And we'll say hides, currently equipped weapon mesh. So if you don't have this here, you'll equipment new weapon, and it'll function properly. Let's say let's say that you have the assault rifle, right? And then you switch to the pistil. The pistol will work properly, but you will see the pistol mesh or the sorrowful still mesh and it'll be overlapping. The assault rifle. So this is just hiding all of these meshes so that they don't overlap. But what we wanna do is we want to make sure that our new one actually shows up. So this is where this gets even more ridiculous. So out of set actor, hidden and Game want to plot a branch. And we want to do this whether it's valid or not. So both of those are going to connect like that. I might want this a little bit further down because it's going to be big. And then what I want to do is out of this branch, I want to take our local current weapon. So remember, local current will happen is this right here, which will get dragged into here, which also equals this, which I'll also equals this, which also equals this, which also equals this, which is this. That's how this can get confusing. Okay? So if our, if our current weapon equals weapons slot 1, and if you remember, in spawned weapon, we are setting weapon slot one to current weapon. If we switch to weapons, lot to that becomes the current weapon. So if our current weapon equals weapons slot one, you might be able to guess what we want it to do. We want to take weapons slot 1, and we want to set actor in Endgame. And we want to leave that unchecked. We want that to show up. We want weapons that one, whatever that weapon is, to become unhidden, to show up. In other words, so what we're gonna do is now we need to copy, paste this five more times. I know, I know people. That's crazy. So there you go. 123456. All that you wanna do here is just slot in weapons thought to open slot 2. So that equals weapons slot. So if it, if it doesn't equal 0 and slot 1, it's going to run down. It's going to say, Well it does it evolve in slot two? If it does, it's going to show it. If it doesn't, it's going to be like, Okay, well does it, it will opens up three, so on and so forth. Three. Coding is monotonous when he gets to be like this and you have so many weapons to check. All right, so now I have that highlight, that whole thing. Comment shows lately equipped weapon mesh. Boom, like that. Okay. Rest assured. This function and this function are the longest ones will ever create. Okay? You can close out, never look back. Let's plug weapon into weapon right here. Just to make sure that data is getting passed through properly. Let's look like a pretty straight line unreal. Oh my gosh. And what we wanna do is we want to take that load out and we want to set it to has weapon. We now have a weapon. Then we're going to pull out a delay node. And we're going to delay for point. Oh gosh, 33 seconds. I'm add a comment here for you. And say allows time. For weapon switch animation. If this doesn't exist, this little delay, then the weapon animation, this code will run so fast that you won't actually see the weapons switching animation. Now we're eventually going to set up point 33 was a good time that I find where it looked pretty good. Weapons is weapon is switching weapon. We're not switching the weapon. And then let's make another boolean right away. Call this can shoot, can we shoot our gun? We can. Okay, it'll be default false. When we start to creating other events in input actions to shoot, we will be turning this on and off because we don't want to be able to shoot our gun. And we're like reloading and doing other things. So we'll say URI enables shooting. And after, or you can't shoot while. Switching leptons want to be able to shoot a gun when you're switching between them will be weird. Okay? So that is all that we want to do there. Cool. Okay, So now, like I said before, our weapon pickups are going to run this weapon pickup event. But what if we already have all of our weapons and we just want to switch between them. Glad you asked. That's when we would have just run equip weapon. But we want to bind those two are keys one through six. So now we're going to do that. So let's go ahead and I'm going to create a new event graph for this, and I'm going to call this action mappings. What I wanna do here is I want to go One, 23, give me a fall of five and you guessed it, 2100 and just kidding, It's six. Alright. Dude, do put these in semi okay. Positions. Spacing them out a lot. Okay, so we've got 1, 2, 3, 4, 5, 6 right there. For one, pull it in. And if a branch as unrelated to call it. And we're going to say is weapon slot filled? If our weapons slot is filled, then we want to do another check just to be extra safe. We want to make sure that our current weapon is equal to weapons Slot 1 equal 0. O, wait, sorry, is not equal. I was like wait, that didn't sound quite right out of my mouth. Okay. If current, okay. This thing right here allow disables like so if you have weapons slot one checked or you have open slot 1 equipped, you don't want to. If he hit the one key again, and this isn't here. You'll just keep running this switching animation. You'll switch to the same weapon over and over again. This is disabling the ability to switch to the weapon that you already have. So if that, if the current weapon isn't already one, meaning that if n equals 2, 3, 4 and you're trying to switch to one, then we want to call her event equip weapon. And the weapon that we want to spawn in this case is weapon slot 1. And then we're going to set that as the current weapon. The reason that we're setting this as the current weapon is because this spawn weapon function will only run the first time that you interact with that weapon. So I have the little floating weapon spawning that actor into the world for the first time. I'm putting, setting all of the locations of it into my hand and all that stuff. I'm setting that as the current weapon. But now let's say I have all six weapons. They're already all spawned. And I just want to switch between them. So now we just need to run the equipped weapon, which shows and hides the match. And also does the little animation. That's all what we wanna do. So that's why we want to, nothing's actually setting that as the current weapon. And since we created this input here, we can set it to be anything specifically. We always want the one key to be weapons thought one. So let's go ahead and copy and paste this whole entire thing and do the same thing for 2, 3, 4, 5, and 6. These are a little bit close to each other. So I'm going to give you a second to do all of this for weapons slots two through six. So I'll see you in a second. Okay. Now, with all that done, you should have first 11 to 2 second 333444. Just make sure all these are the correct numbers here. And then let's comment box around the whole thing. And we'll say key findings to equip weapons after they've ben and initially picked up. So like I've been saying, all of this as back-end stuff. It might not be totally making sense at this point, but when we actually add the weapon meshes, when we actually do the animations to put them in our hands. All of this will all of a sudden or could beautifully and you'll be like, Oh my gosh, this is amazing. Okay, So thank you for bearing with me through this. In the next video, we're going to start by creating our weapon pickups so that we will have something to actually run this event. And then when we can run that event, we can then start creating, um, our animations to actually hold the weapons in, readjust the arms because it's a little broken with the assets that we have. And then we can put the guns in their hands. And then once we have all of that setup, it'll be beautiful. And then we can add some cool functionality to the weapons, actually get them to work. So hope you guys are still in join our way through this. You learned some stuff that he for watching and I'll see you in the next one. 11. Creating Weapon Pick Ups: Hello everybody and welcome back to another video on Unreal Engine for making this first person shooter. In the last couple of videos, we did a lot of copy paste type of scripting, getting our weapons to both appear and hide, just gonna say appear and reappear, but they didn't really make any sense. So in this video, we are going to continue on with that functionality, creates some blueprints to actually give us something to pick up and run the event that we made. So first thing that we wanna do is on our weapon base, we're actually going to make all of our children whatever edits that we make within the weapon base, it will be automatically applied to all the children, whether or not we make them now or later. So we're just going to make them now and you'll see why we're doing that now in a second. So let's right-click on Weapon Base, create Child Blueprint. And I'm going to call this Pistol Pistol underscore weapon. We're just going to keep doing this for all six. So our two rifle and we have a shotgun. You have a sniper rifle? We have a grenade launcher. Why do I forget? Okay. Rocket launcher. Welcome. Okay. I have the underscore weapons that they are linked to Weapon Base or just for nomenclature reasons. Because we will be creating like auto rival impact, effect and auto arrival, this and that sort of thing. All we wanna do so far, Let's open up our weapon. The only thing that we have, we can click on here and say show inherited variables. That's what we want. So we want to be able to see our weapon type and our socket name. So let's go ahead and actually do this one by one. Sock a name. Let's name. This is still underscore socket and we will create that. You know what? No, I take that back. Let's do that later because it's not created yet, so it might give us an error. Sorry about that. For weapon type though, we can set this to be pistol. And for the weapon mesh, we want this to be our click too soon or pistol. There we go. There it is. Exit out of there. We're gonna be doing a lot more editing in here. Later on. Weapon type, auto rifle, weapon mash. It's called assault rifle. We go shotgun. Make this of type shotgun. And let's go ahead and not Schwartz gun, shot gun. And we go as our shotgun. Sniper rifle. Sniper rifle. We got two more. Actually not even going to make this a bigger window here. Who cares? Grenade launcher and rockets slotting in the meshes right now, even though there's no functionality added, just so that way you can visually see them when we need to. Okay, the next thing that we wanna do is we want to create our weapon pickups. So if you you know, I'll show you I have the other projects still open right here. So if I go and hit Play, we're going to be creating these things that we can then pick up and interact with like that. That's great. These things, goals, movie on over there. With our FPS game folder selected, let's create a new folder and we'll call it interact a bowl. And then within that folder I want to create a folder called weapons. Because we're also in our interactable folder going to make M0, that's also going to be interactable. For now, let's stick to weapons. Right-click. So we got a class of an actor and call it a weapon. Pick up, base. Let's open this up and you can drag this along the top because we're going to be doing a few different things in here. So right away, lights with our scene route. Just keep that. Who cares? Let's make a skipping a step. Skeletal Mesh, and we'll call this weapon mesh. And then this is a little bit strange, but we're going to add a static mesh and we'll call this invisible box. And then let's also add a component of rotating movement. And we're going to set the z to be like 130. The higher it is, the faster it's going to go. Z means it's going to sway. Kind of like you can, you can, you can mess with that if you'd like it to do some crazy rotating. But for the sake of this, we're going to keep it rather simple. This invisible box is a little bit strange. The reason that we have an invisible box, because the way that we're interacting with this is through a line trace in some of the meshes like the pistol are very small. And so when I was screwing around with this, I found that it doesn't always hit or work that great because the mesh itself is so small. So this box being invisible means that we will always hit with something else, just give us a bigger radius, then we can hit the E key and interact with even though you can't actually see it. So with this box, what I wanna do is we are going to make it invisible and hidden in game. So unchecked, visible and check hidden game. The scale, Let's lock it and you make it 0.55 of its size. And for the static mesh, we just want the basic one m cube. Since we do have it set to be invisible, you won't actually see it even in the viewports right here. But there it is. It's invisible. But now it's all set up. And we can go ahead to our Event Graph. We don't actually, we need event taken, we need Event Begin Play. If you got rid of them, you can always just call them back. Let's get our player character out of here. Let's cast to be, wait a second. While networking. It should work. Weird, maybe out of just cast to API player. And my spelling things wrong. Why does this thing hate us? Hold on a second here. Okay, so I encountered something I've literally never encountered before my life when I find a solution to it. So if you aren't able to cast to the bp player out of get player character. Go on ahead over to our bp player. Right here on the self. Scroll on down to pawn and auto possess player, go to player 0, compile that. You hit play. Everything is still working. And now out of our get player character, we can cast to it. Now it's thin. Go to the player, which is what I was always expecting to happen. So that was very strange. But alas, we will move on with the right-click and promote this to a variable and call it player. One thing you notice about me is I am very perfectionist, so I am always going to comment box, even the simplest of scripts so that I know what all of this is doing here. So yeah, we just got a variable for the player so that we can reference all of its functions and variables and all that stuff. In here, we're going to create a custom event and we're going to call this pick up. I actually sort of pick out what's going on, interacted with weapon. Okay, just to keep it. So we're going to create a binding that's gonna be called interactive. So let us keep it nice and similar. Strike at our player. If you hold down Control, it'll automatically get it. And then we want to get the event of a weapon weapon pickup already. So if you remember from the last video, two videos ago, weapon pickup is this event that starts off the spawning the weapon, brings it into the world for the first time and then equips it. And since we have this input here, when we call it, It's going to ask which one do you want to spot? And you can see it's asking, now, since this was a class reference, it's, it's getting all of them. So now we have the auto rifle, grenade launcher, pistol. We can spawn any one of these. What we wanna do is we want to promote this to a variable and we can keep the name weapon to spawn. I just don't really want the spaces and it's like that. Okay? After this, we want to pull out a do once node. So we only wanna do this once and we're gonna play a sound today. And then once we play the sound, we want to destroy the actor. So we're going to destroy this pickup. Once we play a sound, I want to promote this sounds uw variable two, and we'll call it pick-up sound. Like that. I believe that's it. So we gotta do in here for our weapon pickups. Actually, you know what? I'm going to be cool. And we're going to add one more thing for flare. But before we do that, let's comment and I'll say runs event in bp player that we know the script. Now you're probably saying to yourself, Well Tim, this is a custom event itself will what is going to call this event. And you'd be right in wondering that. And we will create, this is what we will. We will create an action mapping to the 0x0 in the Iike is what is going to activate this event, which will then activate this event. And that will function in that event. And it'll just be one huge long thing. So before now saying, well, this is like hard. It's really not that hard, it's just very complicated. And so there's a lot of blueprints that are talking to each other to get this sort of thing to happen. If you notice that though, I had the weapons bobbing up and down. So we're gonna do that now. So out of event tick, if you're unfamiliar, so Event Begin Play and event tick, our President Eddie blueprint. If you're familiar with like coding, Event Begin Play is the equivalent to void Start. It runs whenever this blueprint exists, whenever it's called into the world. So that can be perhaps like the second you hit play. Or it can be whenever, you know, in this case, whenever you spawn this weapon. When the weapon is spawned, that eventing and play will run. Event tick runs Once every single frame. So event tick is better for like what you're going to see here when we're, if you're changing certain values, you want the game to be constantly checking for that. So you'd run it as an event tick. We're gonna do is we're going to add a timeline and we'll call this Bob. For bob up and down. Awesome. Let's double-click on Bob. Okay, Let's open up the old Bob. And I'm gonna make this last 2.5 seconds. We want this to loop. We wanted to constantly bow up and down. We're going to adding vector track of vector is x, y, and z. And we can lock and get rid of x and y. We only want to mess with z. So let's go ahead and if you hold down Shift, you will add keyframes. So we're gonna have four of those. The first one is going to be time 0, value of 0. Second one is going to be time of 0.75 and it's going to have a value of, let me just refer to my notes. It's going to have a value of 0.5. This third one is going to be 1.75. Oh gosh, they overlapped. The last one put at time 2.5. Okay? Third one is time 1.75, value of negative 0.5. And then this last one is time of 2.5, value of 0 again. So it's gonna go up and then down. Now this is a little bit jagged. So if we highlight all of them, right-click and hit Auto, now it's going to create a more smooth line like that. And that's exactly what we want. So we can close out Bob, and now we have a new track. And actually, sorry, we didn't name this new track. We can give it a name coming out. Okay, Cool. Let's just call this hover or something. Now we can truly exit out. Out of the update. We want to add actor and local offset and the location we want to be that value. So it's updated. So it's not, it's not it's not running this ad act or law offset. When this finishes, it's running it as an update, so it's constantly running it. And it's this events running every second. And the location is updating with this value like that. So let's go ahead and comment box this as well and say hovers up and down for style. Okay, So we've done so much stuff for like functionality. So here we go. There's some style for you. All right, I promised, and make it look cool. Okay. So we're going to be done in the weapon, pick a base. That's all that we want to do. So we want to start making children to this as well. So let's create a Child Blueprint class and call this pistol weapon pickup. And I'm gonna go ahead and skip ahead. I trust that you know how to right-click and create Child Blueprint class for all six of our weapons. So go ahead and do that and I'll join you in a second. Alright, now with that done, you should have all six. We should have seven blueprints and your total, because one is the base. And what we want to do is just simply open one of these up. And let's go to our weapon mesh and let's do the sole rifle. So what we want are out there like that. Oh, one thing I forgot to do. Apologies is the weapon mesh. I want to be up in the air, so said to be like 150 perhaps. So the value that I had it in the other project is 110, had to go back and check what that number was. So now this is actually going to be hovering above the ground and you notice it is automatically updated here like that. The other thing that I did was I made the y negative 20. So it steps it back a little bit. So that makes this up here just a little bit more centered with our scene roots right there. You can replace the scenery it by just dragging that over. But then if you do that, then you won't be able to move it upward because then this will be the center of everything. It'll be the root. Okay? So the other things that we wanna do in all these blueprints, it's weapon to spawn. We want to set it as the auto rifle. And the pick-up sound is we can begin slot the sense since we set this to be a variable. And there's one called rifle raise, like that. And that's the one that we want. If you feel like it's too loud or too quiet, you can always go underneath pick-up sound. And you can make this like 1.5 or something like that if you want or you can make quieter. It's really up to you. But that's what we wanna do in all of these. So you can go ahead. Once again, I trust you, I'll show you one more time that you can do the rest of them. Give you a little bit of a task here, weapon to spawn. We want to make that the pistol in like these don't have really anything in there yet, but like I said, the functionality will work once at all. It's all set up the weapon mesh. Let's make it at the pistol. So there it is. And the pick-up sound, these all are called rays. So you'll see pistol rays and you want to use the queue that the sounds slightly different every single time. So go ahead and try to do the rest of the weapons, and I will come back in a second. So I apologize again. There's one thing that I forgot to mention. So in the weapon pickup base, make sure in the base so that this applies to all of the children. Go to the invisible box and uncheck the lock and make the y value of 1 before it was 0.5 and that's a cube. We want this to be more rectangular because our weapons are pretty long. We want that to encapsulate the entire weapon. So just make it 0.51.5. And then you can make this invisible again and compile and save it. And then that will be applied to all the rest of them. With that, then we can place our weapon pickups into the world. So let's put the pistil, the auto rifle or shotgun. Oh gosh the shotgun. Know why the shock on lower. Weird. And then we go, this library fall. Maybe just the angle I was dropping in the map must have thought I was placing it lower beneath the ground. Grenade launcher and rocket launcher. So now we have all of our weapons. If I go in and hit Play, you can see they're doing there Bob and, and even thing, maybe a little bit too high still, you can lower that, just change the Z value on the parent there. And then that should fix that. And you can always tune this Abby, make them spin faster, whatever you want to your liking. The final thing we wanna do in this video is actually allow us to be able to interact with these weapons. So let's go into our settings, project settings. Let's go into inputs and let's create a new action mapping. And let's call this interact. And we're going to bind this to our Iike. If we find it. Somebody ease and the alphabet most common letter. Okay, so we want to be in the bp player, in the character. And we want this to be in our action mappings so we can find some space around here. And let's call upon interact. Now, here's some things that we wanna do when we interact. We want to draw a line trace by channel. A line trace is the same thing that we're gonna be doing when we shoot our hit Scan weapons. It's going to draw an invisible line out into the world, but we need to give it a start point and an end point. So let's take our camera component and let's get the world location. So the location of the camera. And we also want to get the forward vector. So the camera's location and the vector that is pointing out straight forward. We're going to multiply that forward vector by a low value. Yes. And this is going to be how far out into the world we wanted to shoot. In this case, let's set it to be something like 200. And then we're going to add these together like that. It hates me. Wait. I thought this was a float. Wait a second. I just had vector a plus vector. And we go vector plus a vector and make that our endpoint. And then our start point is going to be the location of the camera. Okay, so what we are doing here is we are getting the location of our camera component. This right here. We're going to be getting its location. We're going to be getting whatever the direction is forward from that, we're going to be multiplying that 200 units out. So that would be the distance of like here, like starting from here out to here. And then we're going to be adding those two things together to get our endpoint. And then our start point is just the camera's location. All right? And so out of the return value, we want to get an if statement. Because we only want, so if you see true, if there was a hit false otherwise, so we only wanted this line trace to do anything if we actually hit something. For right now we're going to pull out a sequence, even though we're only doing one thing because we want to interact with multiple things. So this is just for the future. And then out of then one, we want to cast to our weapon, pick up base. And then out of our outfit, we're going to break This hit results. And then the Hit Actor is what we're going to plug in to our object. So what brake hit result is essentially doing is it's drawing this line, trace it, seeing, okay, what did this hit? There's all these options for things that can hit. In this case, we're looking for an actor to be hit by this invisible line. And the actor that we want to see if we're hitting is our weapon pickup face. And then if our weapon pickup base is hit and let me just go back to that so you can see if our web me pick up base is hit. We want to run this interacted with weapon. Interacted with weapon. And then if you remember, interacted with weapon, runs weapon pickup, which runs spawn weapon, which then equips a weapon. And there you go. You are now a coding genius. Congratulations. Now if we were to hop in and play and walk up to any weapon and interact with it. You'll notice that we get that sound effect. It disappears and all of that. But we don't actually get to see it in our hands, although it is in our hands, the weapon sockets are a little bit screwed up, so it's actually pointing straight downward and we can't actually see it, but we do have it equipped at this time. So we can do a little bit of a debugging thing to make sure that this works and we'll do that now. So anywhere in our event graph, this is going to be temporary. Just hit seven out of pressed. Let's do a print string. And then let's get the current weapon, drag that out and plug that into that. So now whenever we hit seven, it's going to output to the screen through text what our current weapons. So now if we happen in play, and I were to interact with the assault rifle and I hit seven. We have the auto rifle weapon as the current weapon. Now the pistol and the shot down the sniper. And if I had seven should be the sniper. It that should be grenade. There, the rocket. Now, let's try switching between weapons. So they hit one. That was the pistol, I think Rizzi, sorrowful that we picked up. So hit one and now hit seven. So auto rifle, the second weapon we picked it was the Epistles of it too. And now seven, since the pistol, so it is switching between the weapons. It is doing everything that we want to do. It is working perfectly. Now all we have to do is give us a way to see it actually happened on screen. That's what we're gonna do in the next video and hope to see you there. 12. Making Our Own Weapon Animations: Hi everyone, Welcome back to another video. In the last episode, we created our weapon pickups and all of our weapons switching functionality seems to work. In this video, we are going to be back in the Animation Blueprint so that we can actually see it happened. Hm, instead of just computationally happening in the background. So let's go ahead and do that. Now, the first thing that we wanna do is go to our player arms skeleton located in our character folder. And as I said before, we have this right weapon socket. Off of this socket, we want to right-click and we want to add a socket. Okay, We hit F2 on here. We can give this a specific name. In this case, we're going to call this pistol socket. Let's right-click again at a socket and we're going to add one for every single weapons. So auto rifle sockets, so on and so forth, and add a sockets, shotgun sockets. And then I trust you, I believe you can do the final three TO I'll be back in a second. Okay, now that we have all of our sockets in place, I'm first and foremost in a perfect world, we would have an animator that would make animations that would perfectly hold every single one of our weapons. And then we could just slot those animations in. We do not have that luxury. This pack only comes with, comes with two. It's only has one for a launcher, but the launcher is not the correct launcher and the rifle is not the correct rifle. So what we have to do, we have to do this, the sort of workaround way of translating bones around and creating our own sockets. So that's why we're doing this. If you add a bunch of animations, you will not have to do this just for the record. So what we wanna do, if you remember, if in our bp player, in our spawn weapon, we attach our weapon to the players arms based on the name of a certain socket. And by default that is right weapon, which is this one. Well, we're going to be changing that up so it actually fits in the hand properly. So what we wanna do is we wanna go to our weapons. And in each weapon, we want to change this socket name to the one that we created. So auto rifle socket is what we want. Grenade launcher, make sure it's spelled correctly otherwise. The game way to work. Pistol sockets. Yeah. Match them up with these and spell them correctly. As I said. Unlike me who's awful at spelling apparently, are almost done. Just one more. All right, and then the base just keep the same as that default. One. Next thing we're gonna do is we're going to change these values so that it actually fits correctly. Something that we can do. It said I can show you, which is kinda cool. So under preview scene setting, preview controller, Let's go to US specific animation and we want to use a rifle idle. So, oh gosh, that was way too fast. You probably wanted to be like two or one in here. So we have our pistil socket right there. Underneath our pistil socket, if you right-click, you can add a preview asset and we can actually add our pistil right there. And so you see, right now, That's why we couldn't see our gun when we would interact with it in the last video, like I said, it was pointed straight downward. So we need to make a few edits to this clearly. So go on over to our Details panel. If you don't see the details panel, just go to window details and it will show up. And you'll see here's our name. The bone name is the right weapon. We want to change the settings. So I already did all this for you because I'm such a nice person. This should line up relatively well, but you can do it by hand by like moving it around and all of that. But the locations that I have are negative 0.71. For the x, the y is 0.6, z is 9.3. The rotation is negative 90. The y is 0, z is 0. And that'll look really nice. Now, what we will do in the Animation Blueprint is we will make it this arm disappear and we will move actually the fingers in a good location. But we might, for other weapons, we will be altering kind of where this other shoulder is and stuff. If you want to, you can right-click on here and remove all attached assets and now the pistol will disappear. But you can see now how the pistol sockets in a different location than the right weapon. So let's go ahead to the auto rifle and we'll do that now. So sorry, I'm just checking what the socket was. On the other project. The relative location is negative 1.5, the y is 1.5, the z is 7.6 and the rotation is negative 90. So if you wanted to see what this looks like at PU assets. So rifle. So there you go. Now he's actually really told them that a, that a crazy thing. Let's do the shotgun next. Preview assets. I'm just doing this for fun nowadays. I think it's cool. So see how that looks really stupid. You actually see a move around. If I Preview acid there, it's kinda cool. Relative location is negative 1.17. The y is going to be 2.06, some very really specific numbers here, and then 10.2 and then negative 90. And there you go. There's that and see the fingers clipping through here. So we will fix that in the image, a blueprint and the hand isn't quite up there enough. But we just want the socket we mainly are focusing on is it in this hand, the thumb and these fingers? Is that looking like it's in his poem? That's what we are mostly worried about right here because that is the root, that's the attachment point that we're setting via those blueprints. Sniper rifle is next. Let me go. Now for this sniper rifle, what do we get? The sniper rifle is a negative 0.53. The y is 0. There is 0.87 and the z is 12.9. And then the rotation as always is going to be negative 90. And that looks pretty good right there. As far as this hand, remember we're just focusing these fingers. Grenade launcher, app preview asset, grenade. Know that there are an aid launcher. Hey, Kanzi, click in. X is negative 0.42, y is 1.46, z is 10, and then negative 90. So there you go. It's a nice login grenade launcher in there. Finally, we got our rockets. And then so for the rocket we have x of negative 0.72, y of negative 2.36, z of 13, and then negative 90. So if you want, you can fiddle with it. These numbers work. I did it by hand and now I'm just telling you what the numbers ended up being, but that should all work and then you can just remove this assets and get out of our skeleton. Now if you go into our character and go into the Player Animation Blueprint in the Event Graph, we are going to want to do something out of our other sequence node. Finally, I know. So let's do that now. Da-da, da-da, da-da, da-da. So if you remember, let's actually first plot a branch. If you remember, we created a reference to our player and we have a load out. And so we want to get that variable in here. So let's check if it equals something. If this has a weapon, plug that in there. I'm just trying to like make sure that's not look super ridiculous. Oh gosh. Can probably rewrite this a little bit. There we go and look bad. Okay, So we only want animations to play. If we have a weapon, we don't want our hands is facing outward like this and we don't have a weapon. So if we do have a weapon, let's go ahead and create a new variable. And we'll call this current weapon. And we're going to make this of type load out. All right. We're going to set this to be something. So this is equal to. The current weapon in this blueprint is equal to load out in this blueprint. But we want these two blueprints to be able to talk to each other and make those make a current weapon in this blueprint equal the same thing as load out in this one. So let's go to player. Let's get our load out. And then let's also, oh, actually, I'm sorry. I did it backwards. Instead of making it load out, make it a weapon type. I apologize about that. Yeah. Change variable type. It'll be like it's fine. So we've got a player and let's get the current weapon. So we're going to get the current weapons type and then we're going to get weapon type. Get weapon type and then set that. So let's highlight this and say links. Current weapon in weapon base with Anime Blueprint. So what this is doing here, and you'll see why we're doing this in a second. We are taking this variable and our weapon based the weapon type. And if you remember, in all of the children, we set that to be something. And essentially what we're doing is we're saying whatever the current weapon is, whatever the whatever the current weapons Weapon type is. So pistol, assault rifle, we want to set that to be equal to the variable found within this animation blueprint. Okay? Now if we go back to the animation graph, we're going to unlink this player movement because we want to do some crazy funky things. So we're going to drag it here and we're going to say cash. We're going to cache this pose and we will call it the same name, player movement. What caching poses does essentially is it takes all this data and then puts it into a new name. So if you notice like these only go in one direction, here or here, they're not like nodes that have outputs and inputs on both sides. So now what I can do is I can call upon US cashflows, player movement, and I can sort of continue on the branch to do that, save that as a cash pose and then plug that into something else. So that's what we're gonna be doing. So let's highlight on this and say state machine in state machine controlling players movement. So this is like our first step, so to speak. But we want to make changes to these animations based off of different weapons. So admittedly, this will be a little bit confusing. But if we hold our weapons, like I said, these animations don't perfectly line up. So we will need to make some modifications to some of our bones in sockets in our skeleton. Going to have to move these around to make it look like our guys actually holding the weapons. Because the, there are all of different sizes and we don't have our own animations. So let's take this cash pose player movement. And let's right-click in some open space and say Transform, Transform, modify bone right here. And it's plugged these in. You're gonna get a sort of a little conversion node like this. Okay? This first one is going to be for the pistol. I want to grab two of these and plug them into each other. And then I want to drag out of here and I want to cache. I'll component to local, okay, Sure game. And now we can cache. And then we will save this as pistol pose. Okay. For the bone to modify, We want to get the left shoulder bone be left shoulder. And we want to translate this. So let's this little exposes pen and let's uncheck that. In uncheck that we only wanna do translation. We're not rotating or changing the scale of anything. Instead of ignore, Let's add to existing. And we want to make x negative two, y negative 34, and z negative ten. Like that. Then the other thing that we wanna do is we want to also screw with the right shoulder. Because if you remember, the right shoulder a little screwed up too. As you will see, we want to rotate this. So let's unexposed the translation and unexposed the scale. We don't want to use those. We just want the rotation, the rotation we're going to add to existing. And then we're going to set this to be negative 10. And the x like that highlight this whole thing. And we'll say translating. Animation or pistol Coase. We are low budget. We don't got a bunch of fancy animations. We could just plug in. For all of our weapons. We have to translate to the bones by hand to make them actually look like they do something. So we could actually probably copy and paste this. And we'll translate pistol for auto rifle. Because we still have no animations. Okay? Instead of pistol pose, Let's make it auto rifle pose. Okay. Capitalize what? It's really doing it to me. Okay. Thank goodness. All right. We have a couple of different ones. We have the left shoulder that we want to be negative 20 and z. And that's actually the only thing that we want to translate here when it comes to our auto rifle. Just a little bit of shoulder movement there to move it down and over a little bit. Copy and paste again. And we'll do this for our shot gun. Actually, because we need to them. So let's copy paste this one instead, the pistol. And let's do this shotgun. And I'll stop making jokes. Right here. For cache name shall compose. Left shoulder for the shotgun is going to be negative two, y of 0 and z of three. And then the other bone that we want is we want to start messing with the index. So we want right-hand index one. So like if you notice before, how like the index finger overlap the trigger a little bit, That's what we're fixing here. So we want to take the translation or sorry, no, the rotation. We just want to make this z of 20 and then these other ones. So 000 20. Same thing for the sniper rifle. The left shoulder for the sniper rifle is going to be negative one. And then negative two in the y. And then seven for the left shoulder. And then this is going to stay the same because the fingers so screwed up the same way. Oh, I've got to change this to sniper rifle pose like that. In man for we're now at our grenade launcher. Grenade launcher pose. For the grenade launcher, we want 000 and and I mean, the only good thing is that the same sort of sockets, a left shoulder, and the index of the ones that we have to change. They're not really change like a lot of this other stuff. But yeah, it is pretty tedious nevertheless. And then last but not least, rocket launcher, rocket, rocket launcher pose. And then for the rocket launcher, translation is going to be negative 0.5 and the x, y is 0, and then z is 5. And then that is all of that. So we have all of these blended poses here. You can pause if you get a little bit lost, you need to see the numbers again. And then what we're going to do is one last thing before we get this all up and working. So we want to grab our current weapon. And we want to blend poses. Hopes that other one. Oh gosh, blend. Blend poses by this enumeration. Where is it? When poses by weapon type? Yeah. Okay. This is correct. Okay. We want to blend poses by weapon type and then we want to add pins for all of these elements here, which is all of our weapons here. Boom. And then, which is pretty cool. We can just grab. So for our default pose, Let's just use player movement. For our pistil, we want to use the pistol hose, just this, and then the auto rifle pose, and then the shark compose. And then the sniper rifle cached pose. In then the grenade launcher pose, then the rocket launcher pose. Okay? And so if we do this, it still won't work because we're not actually outputting anything. So we can do is let's go ahead and just cash this again and call this weapon pose. And now let's grab weapons pose. Oh my gosh, game. Work with me and sometimes it hates like using cash poses. Sometimes, yeah, they really search for that sucker. So now you can see that's updating and we're in pistol pose because I guess it must just be pistol by default. A default value of that enumeration is pistol. So you can see it's actually flowing through, it's running through here. Where are we going to Weapon Base. Watch this magic. If I saved it to the auto rifle. Come on. Okay. It doesn't want to update. That's awkward. Well, in spirit, it worked. Oh, wait. There. So you can see how his hands are actually moving. Sees finger, how that moved a little bit much that grenade. You've got the pistol pose. Right there. We're translating these bones. Taking the auto rifle, shot gun, sniper, the grenade, heed, the rocket launcher, and all of that. And so that value of current weapon is going to be linked up to whichever weapon that we have equipped in the game. And so What's happening that Anim graph is that we're controlling our Idle run or caching that into here. And we're taking that data and we're transforming some of the locations of this based on whatever weapon that we have set by this enumeration and that's being outputted out to the screen. So if we did have actually animations, we would just take like rifle run and then just drag that in here. But making this whole step unnecessary. But like I said, we don't have animations. So this is the way that we have to do it. Now one thing that I forgot to mention that is pretty important is that inside of our bp player, um, when we are attaching the actors two components, instead of the default which is keep relative and weld simulated bodies, we want to make sure that these are all set to snap to target and we want to uncheck, well the simulated bodies. So let's go ahead and do that. That's just a small setting that's going to cause a bit of an issue within our script and essentially cause it not to work, which is not good. No blend will do that. And then if we go here and turn around, we have our pistil for rifle, which I think there's an issue with that animation. Shotgun looks good. Sniper rifle looks good. In a lot of really good. And the Racket looks good. We can switch between these now. See that the current mesh is disappearing, the new one is appearing, and the animation is working properly. See the hands moving around to where the guns aren't. You'd actually see that pretty well, especially like that to something like that. So that is all working well and good. Let's go ahead and fix the assault rifle, and then we'll be done with this video. So as a little tidbit, just as a cool little tip, if you want to actually see what's incorrect here, you can hit the semicolon button on your computer. On to the right of L, you can enter what's known as the debug cam and we can detach from our player. We can see that we have an issue with our left shoulder. So our right arm is in is in the correct location, but our left arm is way too far back. And just, just, just not doing that. Great. So gotta fix that. So awkwardly enough, I found out that you probably might not have even had this problem because if I go into my auto rifle weapon, I have it set to be a pistol. So it's doing the pistol animation. If you've run a preview these assets, you can always just switch this in here. And then you can see like if I were to do something crazy like 40, you can see that happen in real time To their hand move up like that. She's kind of cool. Like that. I compile or go back to its default value and then it'll be done. So if I hit play, this might have just been a me problem. There you go. Now our auto rifle is the one being held, and that is also in slot one, so we can pick these up and whatever order that we want. So slot one was the sorrowful pistol, shotgun, grenade, one of those hyper. There we go. So there's a functionality we can actually do anything, but it all works. We are holding our weapons and we can pick them up and it's looking all nice and good. So we're making some great progress here. I hope you are enjoying the class so far and I hope to see you in the next one. 13. Switching Between Weapons Animation: Hi everybody and welcome back to another video. In the last episode, we added some animations so that we can actually visually see ourself switched between our different weapon blueprints. In between videos, I did a couple of really small things in our weapon pick up base, I made the height of our weapon. Mattea was 110, animated 75. This is just personal preference. For me. I feel like they're in a better height now. And then in our player Anime Blueprint, I added this section that says translates bones to hold a different weapons just so that people can see what this part does. Okay, What we're gonna do in this video is going to, we're going to move away from the world of heavy coding and translating all of these bones and doing this crazy stuff. And we are going to add some flair to our project because currently right now if you hit the button, it just kind of awkwardly automatically transitions instantaneously between the weapons we want to actually animate something in plays out. So let's go ahead and do that now. So if you are in our player Anime Blueprint, That's awesome. Go over to our player movement state machine and open that up. And we are going to drag out and we're going to add a state, and we're going to call this switching weapon. And I want to drag a transition to and back. So we want to be able to go from our idle to our switching weapon and then from our switching weapon animation back to our idol walking one. In order to set this up, we need to do a couple of things. So first and foremost, if you remember, if I go to just to basically buy graph is close down. If you go to this equip weapon event that is random, we first pick up a weapon and when we switch between them every single time, you will know that within there we have this variable that says is switching weapon. When this event is run or ran, English is hard, this variable turns true and then after 0.33 seconds, it'll turn false. And we said that it allows time for a weapon switch animation to occur. So it's not instantaneously going from true to false. It allows time for this innovation to occur. So that's what we're gonna do now. So first things first, let's go to our Event Graph and or an blueprint. And let's create a new variable and call this is switching weapon. And I'll make this a Boolean. And all we wanna do it, this is we want to set this to be equal to the same variable that's found within our player. Get is switching weapon. Plug that into that. So now we have a boolean that is in our Anime Blueprint that is set to equal at all times to the value of the one found in our player. So let's do this. And it says, say very little for switching weapon enriched. So pretty straightforward, right? This so far. And we'll add this off the branch of other, other stuff. You might, if you compile like me, you'll probably get a couple of little issues here. That's just because in our enum graph, we don't actually have any animations here. So we're going to have to go ahead and add 11 that we want to add is in our shooter game. Let's go to Shooter game animations, FTP animations, and we want to get rifle equip. So rifle equipped looks like this and we have a broken sound in here. So the one that we want is called, it is called a quip, I believe, SR, SR, sound queue AR clip, and it's busted. So let's equip it anyway. Volume multiplier, we can stay at one for now and said this magnifying glass to actually find this. And let's go ahead and fix it. So search a clip, Clip 1, and then equipped to write n equals 3. So now we say that we put in a queue. And now it works. And I can hear it like that. Pretty straightforward. This one now works. So let's go back to our Anime Blueprint, animation graph player movement, open up switching weapon. It's got our asset browser. And we have rifle equipped here. If you didn't have rifle equipped, are ready, just it'll probably say it's not configured to this skeleton hit Yes, and then select player skeleton and then it will show up over here because player skeleton is the skeleton right here that we created to be attached to this, our character and our character's animation blueprint. Now we need to do is I need to create some states, I mean, until the game. Okay, When do you want to switch to this animation? And what do you wanna switch back to this one? It's very, very simple. We just want to say, Well, are we switching a weapon? If we are switching a weapon, we wanna go from Idle Run 2 switching weapon. And then if we are not switching a weapon, we want to go back. And I'll let should compile and save. So now if we go up here and we pick up a weapon, we should see it animate and inanimate again and anatomy it again. And it's animated. Know that. And we can switch now. Again, the Santa Fe complete waste, it's kinda weird. But it's only sometimes white. That is very strange and will be something around with this animation. Let's see what the promise, okay, I think the problem was persistent because I had the animation file open because now I'm not getting that error. It's working just fine. So who moved the gun out of frame? It'll switch so quickly, you can't even really tell that it's kinda glitching out. Also, another thing that we can check is I have currently weapons Slot 1 equipped, which is the PESTLE currently if I'm hitting one, it's not doing anything. If you remember, we added this script in here to ensure that. So if our current weapon is the same thing as the weapon slot that we have equip. We're not going to run anything. So we can't equip, reacquaint the weapon that we already have. So one doesn't work and two doesn't work, doesn't work for his work 56. And since we have those is valid nodes. Find them, my goodness. Oh my God, easy to get lost in. So he says we have these is valid knows if I were to get rid of those is valid nodes right here. And I'm doing this and then I hit 2, 3, 4, 5 or 6. It will get confused. That sense that we have those. It'll just travel on down to the next one. It won't get confused. And everything works perfectly. So that is all well and good. We are going to just continuing on, add some functionality to these weapons and make them look and sound and feel really awesome. So we'll do that in the next video and I'll see you there. 14. Dynamic Crosshairs: Everyone and welcome back to another video in Unreal Engine 4. It is a brand new day, at least it is for me. So we're going to start this day off right by plane. Some epic first-person shooter music that really set the tone, I believe. So. What we're gonna do in this video and in the next set of videos is we are going to be using the user-interface, making some widgets, some UMG, the hood, whatever you want to call it. So we're going to start this off by creating a new folder in our FPS game and call this UI. Feel free to call it UMG on real motion graphics widgets, whatever you want to call it, I'm going to call it UI. Inside of here, we're going to create two widgets. If you're unfamiliar with what widgets are there, such just like 2D planes, where you can put your HUD and other 2D assets. So we have HUD and then we have cross here. This video, we're going to be making our dynamic cross hairs that will be moving depending spreading out and moving in titer, depending on how fast our characters moving. Before we open up our cross here, what we wanna do is you want to create two new variables, one inside of our character. And then we're going to want to create one inside of our weapon. So inside of our character, we're going to create a Boolean and call it is aiming. This is going to be used in several scripts within the character, where we will fire off different events depending on whether we are aiming, aiming down site or not. The reason we're making it now is because it has some functionality within our cross her widget. The other blueprint we want to open up his weapon base and let's create a new variable and college and bullets spread. Going to make this, I've typed floats. This variable is going to set it to default value of 350. What this variable is gonna do is it's going to be in control of a calculation that dictates how much our bullets are spreading when we're hip firing because we don't want to be totally perfectly accurate. And so this number is going to directly correlate with how far apart are cross hairs are by default. So let's open up across here. And you will see our default 16 by 9 screen size on Fill Screen up here we're going to make this custom and it's automatically, or by default going to set it to be a 100 by a 100. And that's totally fine with me. I'm going to rename our canvas panel by selecting it and hitting F2 and call this cross here canvas. And I'm going to search up a size box, drop that on the canvas. And then I'm going to drag an image and put that on the size box. So you should have a hierarchy that looks like this, where the image is a child to the size box and the size boxes, child to the canvas panel. The size box, we're going to name that top cross here in the image will just name this top fill image. Now by default, images will be set to variables. You can think, you can uncheck that. I don't think I'll be using it, but we do want our cross here to be a variable. With our top crosshair selected. We want to anchor this to the top. I want to make sure our positions are both at 030. Sizes are fine. The x, we're going to make it 0.5 in the alignment. We're going to make sure we click on Size to content, which is going to size this fill image two, these numbers, and we're going to have a width and a height override. And let's make it 1.5 and 20. So now we have our little top Crosshair image right there. Let's go ahead and hit Control W to copy paste this are duplicated and we'll make this one called bottom crosshair. And bottom hit Caps Lock, bottom fill image and the bottom cross hair. Let's go ahead and set this to be anchored at the bottom. And we're making this little flower is down here. Now, let's reset our positions, make sure that they're all at 0. And then I believe the why of this will be one and we'll keep the 0.5 alignment for the bottom. Let's go ahead and make the left one. Now, we've got left crosshair and left Phil image. For the left. I'm going to anchor it to the left. I'm going to reset our positions to be 00. And we're, we're gonna do is we're just going to invert the width and height. So the width will be 20 and the height will be 1.5. And I need to move this over a little bit. So let's make the alignment 0. Yeah. And probably 0.5. That looks good. Yeah, left cross their alignment 0 and the 0.5 in the y. Last but not least, we have the right. So we'll do right, crosshair and right. Phil image. Let's anchor this to the right-hand side. Let's note the size. Its position of 0. Alignment will be x of 1 and y of 0.5. And there we go. Now we ever cross hairs like that. And since we already have this white point in the center of the screen, we don't really need actually put a white dot in the center. For the remainder of the video. We're going to be in the Event Graph and we're going to actually make these cross hairs move around. And the best way to do that is we're going to create a couple of functions that will probably be pretty ugly. So whenever code it becomes ugly, you just stick that bad boy in a function. So that's what we're gonna do. Create a new function and name this move cross hairs or something like that. For this function, we want to give this an inputs of a floats and we'll just call this targets because it is a target value that we're going to be moving toward. And let's promote this to a local variable and call it local Target. Because this script is going to be pretty long. In this direction. I went ahead and hit Alt to break this pin because we're gonna be doing some math, everybody's favorite subject. So at a target, let's add a float plus a float. And let's promote this to a variable and let's call it bullets spread. We're going to link this bullet spread has variable up to our bullet spread variable that we created in the Weapon Base. So this plug-in, the result of that math into our local targets. So it's just passing this, adding it to a value and then setting that as the new value. This is the time where we take out across here. So let's grab our top cross-hair. If you hold down Control, it'll automatically get it. If not, it'll ask you if you want to get it or set it out of here. Let's set render translation. And then out of the translation we're going to right-click and split the Struck pencil will get in an x and a y value. And what we wanna do out of here is we want to get the translation or get transformed, sorry. And then we're going to split this two additional times. So let's split it and then split the translation again. So we now we get an x and y. Plug that in like that. Let's plug the x directly in because we don't want to change it. But for the y, here we go, we're going to interpret too. The return value of this will go into our y, but we need to fill in these. So our target is going to be our local Target. Delta time is going to, we're going to get the world Delta seconds, which is just like the time of within the game, returns the frame delta time in seconds adjusted by time dilation. Time dilation is like if you speed, speed up time or slit on time, this is just like the time occurring in the world. Then interrupt speed. Let's promote this to a variable and we'll call it interrupt speed. And let's make it like, Oh, you can compile first and make it 30. So what is all this doing? So our top cross hair, we want this to move up and down, right? So that's in the y plane. X is this way. Why is this way? So we're keeping the acts exactly the same when we would be moving or whatever. But we want to change the y which is up and down. Interrupt or interpolation is essentially a moving from one value to another over a certain period of time at a certain speed. So we have our current value, which is this y-value that's already set in. And then we're going to have our target value, which is going to be where it's going to move to target value. Remember, is this, and it's going to be adjusted by whatever that bullet spread value that we set in our weapons. It's going to move there over just delta time is always just like the world's time. You pretty much always pulled this node out. And then interpolation speed is just set up to you how fast you want it to move from point a to point B. And so I said 30 is fine. And so that is how that works. That's kind of what that is doing right there. Try to make this. Now it looks super ugly, but it's kind of a funky little script. So let's comment box this and say top. Crosshair movements, something like that. So what we wanna do now is we want to do this for all of our other crosshairs. So let's copy and paste it. And all these are just gonna have slight variations. So let's do the bottom one next. Let's drag bottom over top. It'll replace it. The only thing that we wanna do is the bottom is going to move in the opposite direction as the top would. So let's just multiply this by an integer, by another floats flow times floats. Plug that in as the target, and let's multiply this by negative 1. So that'll just invert that number for us. Sorry, the script is kind of ugly. And then we'll call this bottom bottom crossfire moment. And if you couldn't already guess for our left and our right, what we wanna do is we want to just invert the x and the y, because now we'll be moving on the x plane instead of the y plane. So let's go ahead and grab as a lift cross hair. And the left will just be the local Target. But instead of x and y, Let's break these pins right here. Let's plug the x into our current and then return the x and then just directly plug in the y. So will the left cross hair movement I spelled something. Yeah, 30. And then last but not least, for the right one. Let's name this rights. And all we wanna do for the rights is out of local targets flow times floats, multiply it by negative 1 to invert whatever that other value is. And then bada bing, bada, boom. Now we've got all of that setup. Looking pretty good. With that done, we can go into our event graph and actually call this function into life. So we are going to need, we don't need preconstructed will need Event Construct and event tick. So out of a van construct, which is the widget variant of a vamping in play. So it's like whenever this widget is created, this will run. What we want to do is we're going to get our player character. And then we're going to cast to said player character, the bp player. And then let's set this to a variable called player. Yeah, that's our reference to our player. So now we have the player as a variable in this blueprint here. And then we want to create a custom event right away. And we'll call this crosshair update. Then. We're going to want to run this event off of the event construct right away. So in the crosser update what we wanna do it, Let's get the reference to our player, and then let's get our load out. And remember I told you before about enums and being able to switch them on and off and run different events depending on what it said as well. That's what we're gonna do right now. So let's switch on our enumeration like such. And what I want to do is if we don't have a weapon. So, okay, let's do this. So go to cross your Canvas. Make sure that's set to a variable. Then grab it, get it, and then let's go set visibility and copy and paste that. So we have two of them, plug it into the target. So if we don't have a weapon, and we do have a weapon, if we have a weapon, we want our cross hairs to be visible. If we don't, let's set it to be collapsed. Like that. Here we go. So we only want our cross. There's this show up if we actually have a weapon. So this top script is done. Let's move on to the bottom and we want to do some other things. After we have this show up, Let's go ahead and get the current weapon. And then let's get the bullet spread from set weapon. So we're getting whatever value. So like if I were to go in our weapon bays, right, we have bullet spread said to 350. But I can go in our auto rifle and now I have see that bullet spread and I can set this to be something, some other number and I can change that on a weapon the weapon basis. So what this cross here is doing is it's getting that value. So now we're gonna do some math. Okay, let's do some division flute divided by float. And let's divide that number by 50. And I'll put a comma here and say at counts for bullet spread. Okay, you have to get too caught up on the math and the values. This is just stuff that I did in testing, figured out that worked. Then we're going to multiply this by negative one. So you make sure that it's moving in the correct direction. And then the murmur that bullet spread HUD. I'm going to set that value as that math. So revolt spread HUD is in our move Crosshairs function. Like that, bold spread HUD, we're adding that to whatever our current target is. Okay, after this, what we wanna do is you want to set a timer by event. Timers are slightly different from timelines. We want to make sure that this loops and we want to run this timer every 0.01 seconds, so it's moving rapid pace. And out of the event, we're going to create a custom event. And we'll name this move across here. Or, Ooh, that's also a name that we already used. Let's name that move cross here and let's name this how gosh, moving across here. Actually, let's call it translate. Crosshairs is That's what we're doing. We're actually translating them. There we go. That actually makes more sense. Okay? This is what we actually want to move them around. Okay. It's all looking good to me. I don't move cross here. Let's add a branch because we want to be able to know is our player actually moving. So let's get our player. Let's get our Character Movement Component. There we go. Character movement components is this, controls all these thing. So we changed the walk speed before. You can make yourself jump higher, jump seven times, do budget, whole bunch of different stuff. So we're grabbing that component and there's something built in called is falling. Plug that into the branch because you want to check if we are falling or not. If we are falling, Let's go ahead and do trans late cross hairs. And the target that we want is let's create this to a variable and call it falling target. So this will be the number that we set it to if we're falling. And let's make this negative 60. So remember on Translate crosshairs, we added this input here. So now it's asking for a target of a float value. So what we're doing here is we're saying, okay, if we're falling, start this out as negative 60 and then we're adding that to the bold spread and then setting that as this value. And this value is what our target value will be to move that crosshair to cross the screen. So you don't, like I said, you have to get too caught up on the math here. But that is making it, making that number of a bullet spread. Move across the screen in a way that doesn't look stupid. They ridiculous. So if we are not falling, we want to pull out another branch and we want to see, okay, we're not falling, but how fast are we moving? So scrapped the player. Let's get our players or velocity. Let's get the forward vector after the vector length, actually the length of the vector of us moving. And if this is greater than, one, will check to see if it's greater than one. Because if it's greater than one, that means that we're moving. So if it's greater than one, AKA we are moving, then we'll do our moving. None are moving. Translate, translate, cross here, event. And the target for this one is going to be feel length of our vector. And we're going to multiply this by negative one. So the inverse of that. And then we're going to do some division, divide that by 25, and then that will be our target for when we're moving. And then if we're not moving, let's run that again, trans late crosshairs. And our target is going to be 0 because we don't want them to move anywhere. So this is if caret character is walking, character is standing still, and this one, if character is falling. So we want that to be really big if we're jumping. So that's the biggest one. Biggest value are totally smallest value because it's negative numbers, right? Okay, So there is all of our script right there. Cross her update all of that. Okay, the last thing that we wanna do in here is weight. Do we even, okay, yeah, we're good. So ativan tick, we want to check this every single second. This is where the is Amy thing comes in. It's grabbed the player and we'll say is aiming. Okay? Because if we're aiming down sites, we don't want our cross here show up, right? So let's grab the crosshair Canvas again. And let's do set visibility again. Copy paste. Okay. Let's set this to be collapsed and then set this to be visible. And then the last thing that we want to check is we want to get the player and then get the load out again. And then we want to switch that out again. So if we are not aiming and we have a weapon, then we'll set to be visible. If we are if we are aiming, we'll set that to be collapsed. Which is like you can't see it. The reason that we want to put this additional step in here is that if you don't have a weapon, but you hit the right mouse button, it'll it'll make it show up still, even when you don't have a weapon. So it'll kinda go to the game out a little bit like that. So let's move this down. Comma box removes crosshair. When Amy down site. We don't want to see it more even doubt cite Scott that in that case. So if we hit Play, it doesn't do anything because we need to do a couple of other really, really easy things. So now let's go to our main HUD. Drag that out, and then we want to search our crosshair and drop it on the canvas panel. It's going to show up, look and really stupid. So let's go ahead and anchor that to the center of the screen. Set it to be 0. In 0. Let's set it to be size two content. That's actually really small. I'll set it to be 100 and by a 100 and not size it to the content that's looking much better in an alignment for x is 0.5 and alignment for y is 0.5. So there we go, There it is right there. And finally, let's go to our player, and let's go to our event graph and we should find events begin play. And let's create our widget. We need to actually create it to add to the screen. Let's add the main HUD. Let's go ahead and promote this to a variable and call it main HUD so that we can use it later. And then let's add to the viewport. And then we'll say creates main hood. This is what's actually making the HUD show up on the screen. So now if we happened in play, you won't see anything in if I'm trying to aim. Well, we don't have aimed functionality, but it's not doing anything. Pick up a weapon. Now we have our cross hairs here and they are not moving, which is what we just, we just love to see that happen after we spent all that time coding. Don't you just love it? So let's go ahead and fix that. Okay, So as it turns out, I missed a pretty crucial extra step that we need to do. So in our player, in our event graph on this equip weapon event, Let's go ahead and grab the reference to the main how'd that we made and grab our crosshair. And then what we wanna do is we want to run crosshair update. When we equip a weapon. It's actually not running in less, we do that. So that should work now. And then the other thing that we want to do now that are cross hair is enabled is we want to run across her update every single time that we reacquainted a weapon and switch between them, just as sort of like a fail-safe, making sure that all of that is actually working. So I'm just going to go ahead and copy this, go to Action Mappings paste. And then I'm going to plug every single one of these nodes into here just to make sure that we keep running that event whenever we switch a weapon like this, drag that out there now. So now if I go in, hit save. One other thing, I also forgot to switch this one to the right cross here. But if you were smart, you didn't make that mistake. So let's go over here. It's weapon. And now if we jump, moves, comes back. It's moving around the screen. That always going to be the same size right now. But you can see our crosshairs are moving. And then if you think they're moving too much or not at all, you can adjust some of the math, some of those numbers within. Then here. Some of this math in some of this math will keep the negative one, but like divide by a different number, divided by a different number, set this as a different number, and that will give you slightly different results. So you can go ahead and play around with that to your liking. But other than that, everything's functioning, everything's looking good. So I'll see you the next one. 15. Creating the Main HUD: Hey everyone and welcome back to another video. In the last one, we created some dynamic crosshairs. And in this one we're going to continue on by making our main HUD and making our weapon information in certain stuff like that. So just like in the last video, we're going to start out by making a couple of variables. These ones are going to exist within our weapon base. Let's go ahead and make three of them. So the first two we're going to be integers. One of them we want to make as current ammo. And of type integer. We're going to make another one called current total. And then another one that is called what do we want to call it? Let's call it ammo type, and we'll make this of type text. It's compile so we can edit these. So for current ammo, that's going to be the current amount of AMO that we have in our magazine at any given time. So for default value, let's make that something like maybe like 30. Then for our current total ammo, Let's give us a lot of ammo and say like 244 or something. And for the ammo type, we're going to make something like Racket space, auto space, brackets, something along the lines of that. All right, and so just like before, if we open up our auto rifle, for example, we now have those variables. And we can change these independently. Grenade launcher, shinier, you can change them in and all of that, however you would like already. So now let's go back to our UI folder and let's create a new widgets. And let's call this weapon info. And let's open that up for this one. What do we going to start out with? Let's go ahead. Is this is kind of a big hierarchy, this thing. So let's go to full screen and let's go to desired. Already. The first thing that we want to grab is a vertical box. Let's drag that on top of our canvas panel and we can we replace the canvas panel 0? Now we wanted to do, Okay, maybe I'm kind of like trying to get rid of the canvas panel. A. We can't wait a second. Okay, let's delete. I can just delete the canvas panel. There we go. Okay, let's rename this main box. We want everything to be centered around this box, not a random canvas panel. The reason is that if we have the size box and it has different parameters here where we just want everything to be created on this box. The first thing that we want to do is create a not a statement of our, What's it called? Progress bar? It's going to be called stamina bar by us. Okay? On the stamina bar, we're not actually going to do anything with it yet, but we're going to keep these how they are. I'm left to right is fine. We can change some of the Fill Color and Opacity. That looks fine for now. Let's just keep it, Let's just keep that for now. Next we want to do an overlay and we're going to put the overlay on the main box. And we'll keep that as an overlay and see how it's underneath it like that. So we have this vertical box, the main box, the standard of ours on top, and then the overlay is beneath and we can move them like that and they move in the hierarchy, but we want the overlay beneath. Let's go ahead and do a background blur. Going to put that on top of the overlay. So that lives within said overlay. And then for our background blurry, Let's go ahead and make it a fill like that. So it's filling up the entire thing, the blur strength. Let's set that to be something like 1. So you can see that in there. It's kinda hard to see right now because everything so small. But I mean, that is a thing. Next we want an image and the image is going to live on the overlay like that. And let's just call this background. This is going to fill up everything is well, for color and opacity. Let's make it black. And then for our a value, let's make this 0.35, something like that. So it's creating this blurry kind of black image right here. Moving along in our image size. If you don't see this under appearance, just open up brush. We're going to set this to be 250 by 150. And then since it's stamina bar is so close, Let's select my stamina bar. And then on the Bottom padding, Let's do something like 10 maybe. So there is a little bit separated. And we can actually see like we'll just make that like SharePoint 75 or something like that just so we can see that and we can mess with the colors and different stuff like that. Later. Moving along, let's do a horizontal box. Put that on our overlay, and we'll name this ammo count box or something like that. Let's do padding to the left of negative six. Wait no, to the top negative 6. And then I want to make this kinda centered in here like that. I mean that 0. Now neg negative six because there was some weird things with the text that made it look better in that way. The next thing that we want to do though, is we want to make a text and put that inside of our box. And then for our text, what we want to do is, oh, I see. Let's make the text have negative six and then the ammo count. That's the one that had negative six. That's why Who's the text that looks a little bit strange for our default value for a text. Let's just do 0, 0 for color and opacity. I just do like a little bit of like if you just see this line right here, just put it about right there. There'll be like point 77 for everything like that. It's kinda what I like for the size underneath font size to 64. I don't think we need any sort of shadows or anything like that. So that is looking pretty good. One thing that we do want to do is import a specific font. So let's go ahead and do that now really quickly. So if you haven't already, you can go ahead and download the project files, the course files wherever they're called, on whichever website you are currently viewing this course on, you should see three folders inside of this project files, audio fonts and icons. What we wanna do is in our FPS game, Let's create a new folder and call something fonts. And let's set a color to red. Let's open this up, open up fonts and you'll see paresis peri step bold and semi bold. Let's just drag and drop both of those in there. Just said yes to all. And it's going to create four different assets. One thing that we can do to make this a little bit more pleasurable to look at, is if you click on one of these, you'll see it shows up really small. Go ahead and make this font size like 100, and it'll make it bigger by default. And see that for both of them, something like that. And just save that asset like that. Now, back inside of our weapon info on the text under fonts. Let's do this semi bold one and said now we have this looking thing right there. And my just rename this text too. Current ammo text. Look in good. Inside of our horizontal box, we want to create another vertical box. So let's put that on top of the horizontal one. And we can just we can just keep that name. That's fine. And this is where it gets a little awkward because now inside of that vertical box, we want to put a horizontal box. So we got a whole bunch of different boxes. So let's get back our text and put that on this horizontal box. And let's name this reserve ammo text. Once again, what we want to do here is we want to let me just check my notes really quickly. Oh, I see. I see. I see. What we want to set this as is just a little slash like that. We're going to set this to be the same color. Kinda this line up with this line, it'll be close enough. We don't need to be super perfect here. And plus it's all personal preference for the font. Let's set it to be 20. And we're going to do the semi bold once again. And this should be, I believe it should be left aligned. No, let's make it top aligned and centered. And then that will be looking good. Let's just copy and paste this text. And then I'll put one right beside it. And we'll just say reserve ammo text. Yet another, both colors are available, what's called reserve. Let's just call this. Slash text. And then this won't be reserve ammo text. Let's set this to be zeros 0000 by default. And then let's make this centered and top. That is correct. All of this should be right. 20. Yeah. Yeah, I think looks good. Okay. The last thing we need to do is we need to create one more text. And we want this to be on the vertical box. So now it'll put it underneath like that. Okay, and then this is where we're going to put our kind of fire type. So let's center this one too, and bottom align it. We don't need to put any padding. The color once again, that's sort of like off-white little gray color that I think looks all right, Let's do semi bold. You can always master this stuff however you please. The size of this is going to be 15. The default value. Let's set that to be brackets space, auto and all caps, bracket Enter. So it sets it kind of like that. And these actually aren't centered. Interesting. Probably like one little setting that I still got to redo. It might be with this vertical box. That looks better like that. With these do not look quite correct. They probably this probably has some sort of padding. Let me just check here real quickly, figure out what's causing that and not line up how I wanted to. Ok, so everything is actually the same, but on this slash, do it's actually a slash and then Spacebar and then hit Enter and it'll separate it and it'll be more centered. Now, the other thing is I want to separate these a little bit more from each other. So one thing that we can do is we can create some left padding of like fine for maybe six or something like that. And then those numbers are going to be a little bit more separated. Now, in the render transform for our stamina bar, we're going to make this 1.5 release. I'm going to if that's a pretty good number and then you can slot in whatever colors that you would like. You can make it red, you know, and i'll I'll make it red. I'll make it that red color. And then a style for the fill image. You can get different, different colors in here as well. You can make that red and blue and that will actually give it like a different tint. So yeah, there's a lot of things you can do with the different stamina bar and different options like that. So you can make that look however you'd like to. Okay, So just as a recap, I'm going to show you everything. So we have a main box. And if you have any sort of thing that looks weird, I'll just scroll through all of the settings. Like I said, a lot of this is just personal preference however you want it to look. But these are all of the settings that I have currently. The overlays like that, background blur like this. So you can just feel free to pause if you would like to copy me, or feel free to just do your own thing, because it really, really doesn't matter. This is just making it look the way I kind of tried to replicate it battlefield a little bit by the fonts and things like that. You can do whatever you'd like to do. There is no right or wrong answer. You can just put two texts numbers on the screen if you don't want it to look fancy. And the stamina markers, those are the only two things that we're really putting functionality on. The only script that will exist in this video is binding some of these things. So now that we've gotten through all of that, we're going to bind some stuff to these numbers. We, these are the variables that we created at the beginning of the video. So let's go ahead and do that now. So in the event graph, let's go ahead and get the player character event graph of our same exact weapon info. If you weren't aware, cast to the player, promote to a variable, name it player. Like, such. As we've been doing many times now. But it never gets old. You always want to make references to our nice bilayer so we can keep pulling data out of it like that. Okay, The next thing we're gonna do is we're going to create some bindings. So let's go back to our designer. The first one that we wanna do is get this current ammo text. And then for our text, Let's go to bind and create a binding. It's going to automatically create a function. And we'll just call this get current ammo, because the name that it comes up with is absolutely atrocious. So let's go ahead and grab our player. And then we want to get that load out. And then we want to say equals, equals has a weapon. So we only want to have this script run if we have a weapon once again, because we don't want the game to get confused. So if we have a weapon than we can do what we are about to do. So out of our player, Let's get our current weapon. Whatever the current weapon is in our hands. And let's get the current AML from that weapon, that variable we created the beginning of the video. And if you plug this in and I'll make a little conversion node, and it will do just that. So that's all we gotta do for that. Back to our designer. Let's go ahead and click on Reserve ammo texts and let's create a binding for that. Let's change this atrocious looking name to get Reserve ammo. And then it's going to be, it's actually going to be the same exact thing. So what we can do is we can get all of this scripts to copy it and paste it in here. Plug it in, plug it in. Just like that. But instead of current ammo, we want to get current. Total ammo sets are bigger ammo. In. Then the last thing we wanna do is get this Auto Text bind to create binding. And we didn't actually change the name and that's okay, Let's say get fired type or something like that. And then it's going to be largely the same exact thing that we want to do. Yeah, I keep switching between he's incorrect things. Let's copy that again. Paste it again. We only want to run this if we actually have a weapon, it's actually doesn't it? This and then we'll get the fire and that fire type or gets what did we name that am outside. It should it should be fired type. O will say get ammo type and then that should just plugging directly like that. It will only run if we have the weapon. And so yeah, that is looking all well and good. So now back in our main HUD, we want to create this. Let's grab a weapon Info, drop it onto the canvas panel. Its size to content. Let's go ahead and anchor this to the bottom right. Let's say, think that is a pretty, pretty decent spot. Right? And the position x, Let's do negative 350, position y, negative two hundred and fifty, a hundred and 3000 and 0. All of that is fine. I think that'll think it's fine, actually. That looks pretty good. The last thing that we wanna do here is we want to only have this show up if we have a weapon, which is the usual. So we're going to have to create a reference to our player once again. So let's go ahead and do that really quick. Um, I'm just going to skip ahead because we've done this so many times. I don't know, wasting more time. So see you in a second. Okay, now that we've created a reference to our player, Let's drag that reference out to get our load out again and switch it on again. This is what we did kind of in the last video with the other the crosshairs. And then what we wanna do is let's get weapon info and let's set visibility. Copy paste. We have a weapon, it's visible. If we don't have a weapon, it's collapsed. Plug both those targets in like that. And that should be all that we need to do right there. Bone. So what we can now do is we can go into these different weapons right here. And I want you to go ahead and take some time and put in how much AML do you want the weapon? A half. And how much and what do you want to have total. So change those numbers around and then I'll see you in a second. Okay. So hopefully that wasn't too hard. All you had to do is open up the weapons and change the current animal in the current total ML. So now fit everything correctly when we hop in and play, we equip a weapon, it has whatever those numbers are, and then we switch to the different weapon. And in the other weapon and the other weapon, the other weapon and the other weapon. It will now change whatever we have for the current ammo, the current total ammo, and then our burst. So I just said single auto for automatic spread for the shotgun in the rest of them just say single, those numbers are changing. So if you would like to move those numbers around or make any sort of edits to the visual style of that. Feel free to mess around in the widgets and do that, but the functionality of that is still there. That's the main thing that I wanted to show how to do. So yeah, that is all set up. So thank you for watching and I'll see you in the next video. 16. Sprinting Functionality: Hey everyone and welcome back to another video. Today we are going to continue on with working in our HUD. In the last one, we added different ammo numbers. And while that is all working, one thing that isn't working is the stamina bar. So first things first, we have to actually add a sprinting functionality before we can actually link that up. That's what we're gonna do right now. So to start out, let's open up our character and we're going to go into our movement graph. That's what we're going to be putting this. So we have our walking jumping in now we're going to add our sprinting. Actually before we do anything, we need to add that to our inputs. So let's go into our settings, Project Settings, and then inputs underneath engine. And let's create a new action mapping and call this sprint. And let's set that to our left shift key. So now when we go into our movement graph, we can call upon sprint like that. And we can start doing some things. First things first, we want to pull out some branches because there's certain things that we, well, we don't want to be able to be able to sprint if we're doing some of these things. So let's plot is aiming and say is not aiming because I just like to run into the true branch a lot. So if we are not aiming, then we're going to make another check. And we're going to say, Well are we are reloading. This part is optional. Some games allow you to reload while you're sprinting. Those one that we're making will not. So I'll just put optional disables, sprinting well while reloading. So if you want your game to be able to, if you want to be able to sprint and reloaded the same time, you can remove that part. It's up to you. Some games have a like you can interrupt the sprint or interrupt the railroad by spreading all that's up to you. But we definitely do not want to be able to Sprint Hall we're aiming that would look ridiculous. We're going to pull out one more branch here. And we're actually going to store this inside of a macro. Macro is different from function a little bit in that it's, it doesn't have these execution wires. So you can have inputs and outputs, but it doesn't have to have a white execution wire. It can output this type of data. So we're going to plug this into a, we're going to return a condition, a Boolean. So let's create a macro and let's call this are, we exhausted question mark. So when it comes to our game, we have the stamina bar. And so if the stamina bar runs out, we won't be able to sprint until it reloads to a certain value. So let's create some more variables and we'll say is exhausted. Question mark. And let's create another variable and call this energy level. And we'll make this of type float. So let's go ahead and let's grab out is exhausted in say, not just makes it more coherent for me, personal preference. And let's grab our energy level. And let's say if this is greater than or equal to, point to, what we can do is you can pull this out and say, and remove those. And then let's pull the, plug this on the output and overturn that. And we can just keep the name return value. So what this macro is doing is it's checking to see if both of these conditions are true. Both of them, you can do one or the other by pulling out or, but in this case we want both of these to be true. So in order to sprint, what this is essentially saying is that we cannot be exhausted, will turn that is exhausted variable on when energy level equals 0. And the reason that I'm setting this to point to is because I want the stamina bar to refill 20% of the way up before we can sprint again. Because then what will happen is that the stamina bar will go up like 1% and there'll be able to sprint again. And you'll only be able to be only be able to sprint for like 0.5 seconds before it runs out again. So I want that I want to give it time for that to refill little bit before we can start sprinting again. So let's go back to our movement and we can actually pull out this macro and do it like that. Now the reason that we created this into a macro, so technically speaking, we could have just done it like this. It means the same exact thing. But by storing this data in a macro. For one thing, it's a lot cleaner, seeing it that way opposed to this way. In number two, we can now pull this out a bunch of different times and use it a bunch of different times. Whereas this we'd have to copy paste this long script every single time. So that's probably a pretty big tip. I remember when I first started learning how to do this, I really got caught up on like okay, like I have to use a function here are blue paint, a Blueprint Interface or Event Dispatcher are like all these different things. And I gotta put this in a macro. A lot of those things exist just for convenience. So like storing in a macro, like I said, it saves space and it allows you to use it more than once without trying to find it and copy pasting this, this long piece of code. But plugging this in here and doing that in using the macro does the same exact thing. So a lot of that just comes down to personal preference. In, as you get more experienced in scripting, you try to do things that are more efficient. So I'm sure even in here, like you can accomplish the same thing. I'm trying to accomplish multiple different ways and you might be able to find a way that's technically speaking more efficient than my way. And that's okay. But this is a way that I know how to do it and it works. So that's what we're gonna do. Okay? So if all the of these conditions are true, all right. We were not exhausted, we're not reloading and we're not aiming, then we can start sprinting. And once again, we're gonna do this inside of a function. Not because it's super complicated, but because we can then call upon it every single time. All right, so in start sprint, we want to check one thing. Let's get the character movement components and we'll say is falling. And once again, we'll say not cuz I like it that way. I don't like going out of the false branch by default. Like going out of true because it keeps the lines nice and straight. So if we're not falling, aka if we're in the air, I don't want to be able to sprint when we're in the air. That would be very unrealistic. Okay, So then what we wanna do is let's grab the Character Movement Component again. And let's get, let's set max walk speed, this value in here. And let's promote this to a variable and we'll call this sprint speed. And by default I'm gonna make this one hundred, one hundred, ten hundred. So our default max walk speed is 750 in I'm setting it to be 10000. And then we have this, or maybe we don't. Okay, let's create a new variable and say is sprinting that we made that already as we didn't. And it's a Boolean. And we'll set this to be true. Compile and Save, and it's all we have to do. So once again, let me just reiterate this. I can do this and we can make it look like that. Okay? Or I can just get start sprint. And it'll look like that. So we can do it like this every single time or we can store that data in a function and just do it like that. So we don't have to get this big, ugly code every time we got much space that saves. And then we don't have to copy paste this every time we can just keep calling the function. So that is a big tip. Okay? Don't get caught up on like always use an event is batteries making a function in Lego and try to understand all this up. It is, it is for convenience factor. Okay, so hopefully that makes sense. Cool. So now we are sprinting. What we wanna do now is we want to get our load out. Because you want to have two different things happened depending on if we have a weapon or not. So let's switch on or load out. Because we still wanna be able to split this sprint. If we don't have a weapon. Okay? If we don't have a weapon, we're going to pull out a timeline and we'll call this stamina. Okay? If we have a weapon, we want to stop shooting our gun. Because when you run, you know what? I'm actually going to leave this part out here for now. And then I'll show you what it looks like without it. I think that'll be pretty cool actually. So we have this stamina thing, we'll, we'll save this for later. Alright. Can make a note or something like that. I don't know what we'll figure it out. Okay, in the stamina bar, Let's open this up and let's make this 10 seconds long. It's be able to run for 10 seconds and create a Float Track. And we'll call this stamina amount or something like that. Okay, Let's go ahead and create two keyframes. First will be at time 0 and a value of one. And the second one will be at a time of 10 all the way in a value of 0. So if we click on these little things, you can actually see that moving from that value to that value. So it's moving from a 100% of itself to 0% of itself over the course of 10 seconds. We want this to play in that play from start, because if we played from start, it would restart it every time. And we want this value to move up and down. Like constantly. So if we write here we sprint a little bit, it's going down, then we stop and then it'll come back up. And then we reached the end. It'll do this and it'll come back up a little bit and go back down. If we hit play from start every time we hit Shift, it would start back up here and give us a new ten seconds, which is not what we want to happen. So cool Cuckoo, cuckoo. So we have our timeline. Out of the update. Let's set our energy level, this variable that we created. Let's set that to the standard amount. So now those are directly correlated, pulling out of here. And let's say equals if our energy level equals 0, AKA if we run out a lot, if, and then this is going to come out of the finished. Let's rewrite this a little bit like that. Okay, so now if our, if we run out, we're going to run an event called exhausted. So now on the other side of your timelines have a whole bunch of cool things. We're going to create two custom events. We're going to call one movement stopped and other custom event and call this exhausted. So if our energy level equals 0, we're going to run this event exhausted. Cool. Let's do movement stopped first. If movement is stopped first things first we're gonna say, we're gonna ask if we're exhausted or we exhausted. People wanna do two different things based on whether or not we're exhausted. All right? If we are, if we're not exhausted, sorry. And plot a sequence. And what we want to do is we want to 0, we actually have to create this. So we created a start sprint. We also need to create a stop sprint. So let's do that. No, create a function, call it stop sprint. And this is going to be a rather simple. Let's just get the character movement components. Let's set max, walk speed. And let's just, let's actually promote this to a variable so we can, so if, if you would like to change it to something else, you can do that very easily. So max walk speed is 750. So the default was 600, but we said is 750. And so it'll keep resetting it to 750. So this way you don't have to go into the function in like retype it in manual. You can just change the variable and it'll dynamically set for you every single time. So what makes variables nice? And we want to turn this is sprinting off, and it's all we wanna do for stop sprint. Let's go back here. So now if we're not exhausted, Let's go ahead and stop sprint. All right, and then this is going to plug into stop. It's going to stop the timeline in its tracks where it is. It's gonna say hold your horses over there. Then we want to have a delay. Okay? And we want this to pause. So let's promote this to a variable and we'll say stamina region. Pause and we'll set this to be like two seconds. Okay, so what movements stopped is doing here? It's going to check, are we exhausted? If we're not exhausted, aka if this number is still above 0, AKA if we're still somewhere in here and we're not here, then what's going to happen is we're going to stop our sprint. We're going to set our max walk speed back to normal. Then we're going to wait for two seconds. And then this thing is gonna go in reverse. So say we're sprinting, we're sprinting, we're sprinting, we're sprinting, we're sprinting or stem is going down, then we stop spinning. It's going to stop right here. Wait two seconds. And then it's going to throw it in reverse and go back up and give us some statement back. That's what movements stopped is doing. Now if we are exhausted, all right, then we're going to set is exhausted to be true. So now this has nothing to run out of. It's not going to run this, it's gonna run this. What we wanna do is we still want to stop sprint. We want to set our movement back to normal. And then what we wanna do is want to make a delay. And we're going to have a different timer depending on if we're exhausted. So its promises a very variable. We'll say exhausted timer. And are exhausted timer. So we're huffing and puffing instead of two seconds, Let's wait like five seconds. And then we will turn is exhausted. Back off. We've waited are five seconds, we've got our breath. Okay? And then we're going to reverse from the end. So instead of just reverse, so like this can get reversed at any point. This event is only going to run right here if this equals 0. So we want this to make sure that it's reversing from the end, which is right here. Value, our stamina is at 0. So bada, bing, bada, boom, that's how we do it. That's everything. That's beautiful. The only other thing we gotta do is we got to make sure that we cannot shoot our gun if we're sprinting. Because otherwise a little shoot off away to the left. And it'll look really, really stupid. But for the time being, I kinda wanna showcase that because I think it would look hilarious. And it's kinda fun to like show bugs and to show like how you have to be so specific with computers. Just think of everything to cause things not to be ridiculous. So the last thing that we wanna do is we just want to go into our UI folder. And let's go into our weapon info. And let's select on our stamina bar. So we want to, we want to actually correlate this. And let's go to the percentage right here. And let's create a binding. And let's say gets, gets stamina is a fine enough name. And all we wanna do this and be really easy to get the player. Let's get our energy level and employ that in bada bing, bada, boom. Mr. worldwide stepped into the room. There we go. That's all we had to do. Okay. So let's go over here now for this works. Oh gosh. Oh, you know, I've gotten ahead of myself. Forgot one thing. Does go ahead and do that now. So this is what happens when I try to purposely glitch out the game end up reckon myself is what's happening right now is since we can only see the stamina bar if we have a weapon and we don't have anything that happens when we have a weapon. So for the time being, just make sure both of those go into play and then make sure energy level is set to one. I never I don't think I ever said that. This is moving in percentages. Okay. So don't set it to be a 100 or whatever, set it to be one. So now what happens? We walk over to a weapon and we pick it up. And I have print strings to show the speed. So you'll see like a 1000. And our thing is going down like that. Looking pretty great. But if you notice, we pick our hands off and we hit Shift again, there's no way to stop from being exhausted, but you saw up there set of 750. So what I wanna do is we can plug released and put movements stopped in there. But I want to be cool in professional looking because a lot of games have it where you don't have to hold down shift the entire time. You can just tap on it and that's personally what I prefer. So that is what we're going to do. We're just going to have a tap Sprint button. And then once you lift your fingers off the keys, you'll stop spinning. But first and foremost, let's go ahead and comment box this and say sprint with three Jan or 18. Stamina, bar, like that. Okay, like that. Feel free to make any edits like with this part or whatever. If you, if you like, having to hold down sprint and then releasing it, like I said, you can do this and the disco movement stopped. And then that will work when you release the key. But I don't like that. I don't like holding down the key the whole time. I like tapping it and then letting go. And then they're letting go of w. Like how a lot of games work, toggle sprint. So let's do that now. So lets you run an event tick. Okay, And what we're gonna do is we're going to make a macro for this. And if this macro is true, then we'll run movement stopped. What does this fancy schmancy macro that you say? Well, I'll show you. So let's go ahead and create that. And we'll say, have we stopped moving? Like that. What we wanna do here is we want to get our player controller. And then we want to check is inputs key down. And the key that we're looking for is w. If w is not being pressed down and we are sprinting still, then this will return like that. So we have to be sprinting, which is initiated by hitting Shift. So that's one of our parameters. And then for this to return true, we also need to not have the W key down. Alright, so let's go into this. Have we stopped moving? It doesn't want to drop it in for whatever foot there we go. There it is like that. And then we'll comment box, just this one little part. And we'll just, we'll come at this and say connected to timeline. So movement stop. We'll then check if we're exhausted or several, Stop the Spread. It'll do all that for us. Coming back. So we'll say checks to see if W key is released while sprinting. So if we're sprinting, but we let go of w, which is what naturally happens. We'll stop sprinting. So let's go ahead and do this now. Our key and now we're sprinting were spinning and my, my pinky is not on shift right now. I let go of w and it stops. And then it goes back up. And then I'm sprinting again, hit shown shift. It's a toggle. Here we go. Like that. And so if I keep doing it and then it runs out, it's going to run that exhausted and 750 and I'm hitting it again. It's not sprinting. Not sprinting. It's not sprinting. It gets to 20 percent and then it lets me do it again. So it went up a little bit further before I was able to do again. So all that functions great. All the functionality is correct in, in-place. So here's our script for this. And then our script for this lesson we're going to add is one extra thing right here later on. But yeah, that's everything. So in the next video, we're actually going to add an animation to make it look like our characters sprinting. And then we will have all of that correctly set up. So I'll see you there. 17. Adding Sprinting Animations: Hey everyone and welcome back. In the last video, we added some functionality to allow our character to sprint around the map. But we implemented it in a way where he can only sprint for a certain period of time before he gets exhausted and then slows back down. And then we link that up with our stamina bar. We have a couple of different parameters in here. We made it like a more toggle type of sprint where we can just tap the key and then once we let go, we stop walking. Our character will stop sprinting. Those types of little things are up to you. And we also implemented it in a way where You can't you can't sprint if you're currently reloading, which again, personal preference, but that's how we built it. Feel free as you get more confident in your scripting skills to make it however, you would like him fit to your personal preferences. So what we're gonna do in this video, this one's going to be pretty short. All we're gonna do is we're going to link our is sprinting Boolean, which is set to be true right here at my get rid of these print strings actually set true right here and we start sprint. And then when we stop sprint, it is set to be false. We're going to link that up to our Anim graph so that we can do a running animation. So that'll be pretty cool. So it turns on right here and then stops right here. So let's go ahead and do that now. So all we need to do is go into our character. Let's do player and I'm blueprint. Let's go to our event graph. And then outside of this, then one with our other player references, let's drag in player and we'll go Gets is sprinting. And let's promote this to a variable and we'll keep it the same name is sprinting. To make it coherent to us. You know the drill by now, we're gonna variable for sprinting animation. So we know what all these things do. An async comment box part from each other. That looks nice. So now let's go back into our player movement. So go to the Anim graph over here, find our player movement state machine and we're going to add a new state. I'm going to drag switching weapon like over here, because this new state is going to connect to both of these. We want to create transitions for both because we can sprint if we switch a weapon while we're switching weapons, that's fine. Okay, So we want to add nodes going there and back for both of them. So they're back and they're going to have the same exact rules. So if we're idle and we want to head over to sprinting, let's just check will are we sprinting? If we are sprinting, we're going to run this animation. If we are not sprinting, then we want to go back to our Idle Run Animation. Same thing goes for here, so forth, switching a weapon. And we start sprinting. You're just going to say, Well, are we sprinting? And then if you wanna go on the way back, sprinting. Not sprinting. To simple as that. Last thing we need to do is just make sure that it's actually animation for here and we don't have one-character skeleton. So let's go to a shooter game. Animations, FTP, and it's called a roadie run. It's the one rifle roadie run right here. Sine to the new skeleton player skeleton for open this up, this is also going to have broken sounds. So if you remember how to do that from previous videos, actually, we should probably have that one in here run. Well, there you go. And we can make this a little bit louder, like maybe like 1.5. The footsteps are a little bit louder for running. So sure. So now it sounds like this. Pretty cool. So now we should see that wrote Iran right here, plug that in like that, compile and that should be everything. Normally feel like I forget something but I think that's everything. So let's pick up the gun. And now same thing had Sprint. And there we go. Now we're running. And then we let go. W o, SMS, weird going on there. When we stop sprinting, What the heck is going on. Okay. So I figured out the problem instead of his sprinting and this one we're going to use is switching weapon. All right, so on the way here is switching weapon to is sprinting. We're going to say is not switching weapon. We can transition from switching weapon to sprinting if we're not switching a weapon. And we can transition from the sprinting animation to this switching weapon animation. If we are switching a weapon. So now this should work. There we go. The only other thing we have is jumping animations. So it is running through the air. So this video isn't too long. Let's just go ahead and add the jumping animations right now so we don't look stupid. So let's create some new states at a state and we'll call this jump, start. Another state, jump loop, and then a final one. Jump and go. And these, unlike the other ones, that they're not moving oh my gosh. Over though. They're not moving from forward and back. These moving like a little triangle like that. I don't know if we did we get is in air. We did not. Okay. That is one variable that we definitely need. Yeah, okay, So in our urban graph, let's go ahead and try Get Pawn Owner. And then let's get our movements components of that pond, which is going to be our player. And we'll say is falling. And then what's promote this to a variable in college is in air. And hit the wrong key there. Go. Something like that. I ended up controls, jumping animation. Bada bing, bada, boom. Go. Salary of that. Yeah, it's going to hate us for a second, but rest assured what we find. So let's do this if we're in air. So we'll transition from the run to the jump start, to transition from the, we have to slot these innovations in no way. Yeah, we do. Okay, so let's go ahead and do this first because it'll get confused if we don't. So let's just type in a jump in the same folder and we have JumpStart. We want the rifle one Jump, Start loop and end, such as assignees to our player skeleton. That and then we can slot in our sounds. They actually have jumping sounds. But you, you know, you should know how to do that by now. So I trust you. There's your homework for the day. If you want to do that. Jump blues players skeleton retarget there. And then rifle a jump N? Yes. Yes, yes, retarget? Yes. Okay. So now let's plug these in. Jumpstart. I'll go with Jump Start. Loop will go with jump, loop and jump and we'll go with, you guessed it, jump end. Okay. Now need to make transitions between these. So what we're going to search his time, remaining, time remaining in our Jump Start Animation. And we'll say is less than 0.1. So if there's less than 0.1 seconds left in this jumping start animation, we're going to move to the jump loop animation. Okay? And then to move to jump, and we're going to say, are we not in air? So we will have the jump loop, Innovation, keep looping until we're not in the air anymore. And then we'll be able to transition back from jump and to idle. If there is, let's say, less than 0.25 left in our jump animation. And then what we wanna do is we want to be able to go to jump from sprinting as well. And then that's going to have the same parameter of just being like, Well, are we in the IR file and save? And now we happen in play. And we are done. And there's something strange going on with that. But for the time being, let's just sprint. It's working. And then we jump. He does the jumping and then he's still sprinting even after the jump. And if I let go, he just laughed. So all that works perfectly, working good. I might try to figure out if there's something weird going on with equipping the weapon. And if there is, I will get back to you on that. Sometimes there's errors in my program that might not be persisting in yours, but I will fix mine just in case I told you something that is a little bit faulty, but yeah, thank you for watching. And I will see you in the next lesson. 18. Making Ammo Pick Ups: Hi everybody and welcome back to another video. In the last video, we started finishing up most of the animations that we're going to need for our character's movement. And in this one we're going to continue on by adding a couple more pickups. This time, we're going to add some functionality to be able to pick up additional ammunition. So we're going to do that before we get into that though. At least for me in the last video, I got an issue where if I picked up a weapon, the character does this weird jittering where it kind of moves the gun from right to left awkwardly if you didn't see it, I'll do it again. Is that weird sort of kick right there. And it does it every time you switch weapons. Now I went ahead and I compared this script to the previous project. And the previous project was the same exact thing as this one, at least to my knowledge and I wasn't getting that issue. If you are getting that issue, you can ignore this part, but if you are, you can go into the Player Animation Blueprint and the Anim graph player movement and that state machine. And you can actually just remove this top transition from switching weapon to sprint. What that will do is that if you are sprinting and then you switch a weapon, or if you're switching weapons and you're still spinning, instead of traveling from here to here, it'll go here, then to idle and then back to sprint. So now if I happened in play and I pick up a gun, you won't get that issue. And you'll still be able to run and switch weapons at the same time. So do the weapon switch and then go back to the sprint immediately. So all of that works just fine. So potentially this transition was redundant because it's going to go here to the ureter here anyway. So that out the way, I think that's the only kind of issue that was had there. But what we're gonna do is we are going to create some blueprints to add some weapon or some ammo pickups. So underneath interactable, let's create a new folder and call it ammo. And I'll set it to our color. Then inside of the animal folder, Let's make a blueprint class of type Actor. And let's call this ammo pick up base. How is get confused with pickups? One or two words. It's it's one word if you're referring to like a truck, but it's too if you're saying Pick up to 240 phonics, you all, okay? What we're gonna do is we're going to add two different static meshes here. So a static mesh, the first one will be AML mesh. And we can drag this onto our scene route and make this one the default. And then underneath here, let's make another static mesh. And we'll call this one hit Inbox. So these textures are small as well, these meshes or small as well. So we're going to do the same thing we did with the weapons were there's this invisible box right there for our ammo mesh. This is going to be a parent, so we don't need a slot anything in. But I'm going to lock this and make it 2.5 times the size because these are very small. Okay, so then for our hidden box, let's go ahead and slot in just the one m cube is going to be pretty big. So let's go ahead and we can keep it locked and make it half of its size, 0.5. And then we're going to set this to be invisible and hidden in game. All the collision, everything should, should work just fine for the most part, I think that's all we need to do. Let's go ahead and actually head back out here and into our data folder. And we're going to create a new enumeration that we'll use for this blueprints. Let's go blueprints enumeration then go E, and let's name this ammo type. All right, and then we're going to create six enumerators. So 1, 2, 3, 4, 5, 6. And we'll call this pistol ammo. So we're going to just name each one the weapon and then the ammo. So auto rifle, animal, shot gun. Because the way I'm creating it is you won't be able to interact with a certain kind of ammo unless you have that current weapon equipped. That's why we're creating this a sniper rifle Anno. So we want to give the way, give the game away to identify what ammo. This is grenade launcher or what AML we're trying to interact with in sync that up with whatever weapon we have equipped. And finally, rockets, launch enamel. Goal. Then our MO pickup base. Let's create a variable, variable and we'll call it ammo type. And we'll make it of type, animal type like that. Good. Okay, Now in the event graph, Let's do some stuff in here. Under the beginning play. Let's create a reference to our player. Let's cast to the player and promote it to a variable that you should be very well versed in. Casting. And making references here. By now, should be a pro at it. Do this. And also knowing why we do this. Okay, now let's create a custom event. And we'll call this pick up ammo. This is going to run when we try to pick up ammo. And what we wanna do is I want to create an event or a function, sorry, that's going to check whether or not our current weapon is equal to the type of ammo that we're interacting with. The easiest way to do this. In my opinion, without making everything too complicated is we're going to do this inside of the weapon base. So let's go to weapons and go to weapon base. This will get a little bit hairy and we do need to organize these after a certain point. Okay? So let's create some new variables. And we'll call, these will all be integers and we'll call them pistol. Pick up amount of type int. And that we want to create a bunch of these, one for each weapon. So auto is that now I'll rifle pickup amount is to be kind of ugly names shot gun. And he controlled WT is to duplicate it quickly. Sniper, rifle, gray launcher, and then finally rocket launcher. Pick them up. Well, these are going to be in charge of, let's just say it's put in a category now, Emma. And I will just drag all these in here. I don't like how it's doing that. I want to put them in the right order. So pistol and then auto rifles and shotguns, Sniper. Okay, good. Cool. So we can do is we can set these three different numbers of how much ammo do you wanna pick up? Based on like when you pick up a center for the pistol just, let's just say 24 bullets for now. The auto rifle, 60, the shotgun. Let's do 16. I'm trying to remember what I put. Trendy like to magazines for each of them, to rockets. And you can change those to your liking. All right, now what we wanna do is let's create a function. We'll call it ammo. Pick up. Like that. Alright. Let's yeah, let's make an input and call his MO type. And we'll make it of type, AMO type, like that. Let's drag it here and switch it on. So now you should see all of our pistil ammo, this and that. So if this is set to be one of these things, it'll run one of these executions. Okay? So all of these are going to be the same, which is Larry slight variations. So out of pistol ammo, Let's pull out a branch. And let's say skip the weapon type. And we'll say equals so far current weapon. The weapon if our weapon type, which is also like the current weapon, that equals the pistol, then what we wanna do here is we want to grab current total ammo. Look at the set. We want to take the pistol pickup amount and the current total ammo. And we want to add these together and then set that as the new current total AMA. So let's say we have like, Oh gosh, this is actually quite a bit of math. Let's just say for easy math sake, we have 10 bullets in reserve. 10 is our current total ammo. Total ammo being 360 in this case. And we had a set to 24, so 10 plus 24, that will then set that to be 34. Math is power. Okay? And then let's make an extra check on this, okay? With this selected and let's add an output, and let's make it a Boolean. And then we'll just have this say true or we can have it say success if you want to be cool. Right? So like was this successful? If it goes through this branch, was it successful? Yes. It will return true. If it comes out of here, then it will say No, it returned false. Oh sheesh, we should that's unchecked. Ok. And then we'll say adds pistol ammo. If her here adds ammo. If this still is picking up Pistol ammo. Like that. Okay, Seeing it a look at that script like that. So now all we need to do from here on out is we need to do the same exact thing for auto rifle shock on all of our different weapons. It'll look exactly the same as this. All we need to change is R. So for auto rifle will do change it to auto rifled pickup amount and for the weapon titles which had a rifle. So I'm going to give you a little task. I'm going to do this myself. I'm going to give you some time to fill in the rest of this function on your own. So I will cut forward a little bit, get back to you. So have fun with that, and I'll see you in a second with the answers. All right, So this is what the final function should look like. So if ammo type is set to pistol at around this one on a rifle down one and so on, so forth. So we had to change, like I said, pixel Picker, male amount, current total pistol or rifle, auto rifle, shot gun, shot gun, sniper snipers, grenade, grenade, rockets, rocket, and then yeah, all of that will run. I have a typo here. Okay, cool. So now all we gotta do is let's go back into our pickup base and let's drag out the player and let's get the current weapon. Remember the current weapon is a reference to this weapon base here. So since we have that out, we can now call ammo pickups, this function that we just created. And we'll pick up and call that. And it's going to be asking for an ammo type, right? Because we put this in, put in here. So it's asking for one. We continually slot this is anything but we created this variable, remember? So let's plug that in. So the reason why I had it that set as an input is so that we can plug this variable in. So when we make the children to this, we can set this dynamically on the children so that this value will always change and then run the different parts coming out of that enumeration. And then out of our success. So let's say if, so, if this returns true, meaning that you get one of these success things, then what we wanna do is let's play a sound to D. Let's promote this to a variable and we'll call this pick, pick up sound. So we can dynamically set this in the children as well. And then let's destroy the actor like that. And then we'll just come in boxes to say adds MO amounts in Weapon Base. Just so we can remember what that does and where it is. Sitting like that. So that's all works. So there we go. That's all we have to do in our pickup base now. All we have to do is make the children. So MO and we'll pick a base, Create Child Blueprint class and we'll call this pistol ammo pickups. And what does keep on doing this for all of them. All right, so if this is done correctly, you just right-click on AML, pick a base gray Child Blueprint, and then we rename them all rifle, grenade, pistol, rocket shotgun, and sniper rifle. So now you have to do is open up one of them, any one of them. For our ammo mesh. Let's look up assault rifle pick up. And we get these sort of magazines here like that for the ammo type. Let's set that to auto rifle ammo and the pick-up sound, we should have a pickup. See there's these right here rifle and we'll pick up cue like that. If you don't like the volume of that, you just go in here and change the volume multipliers so you can make it whatever you want to or whatever you want to, your personal preference. And then it will apply to all of them. So that's all you have to do for one of them. So yeah, just go ahead. Slot in. I think I sound okay. Pick up like that and we'll type grenade sound. Grenade launcher am a pickup. You want to make sure you have the QRS because then it'll have like multiple different sounds. At least it should. That's typically how queues work. So yeah, just go ahead and fill in the rest of those and I'll be back to you in a second. Okay, now that we have slotted in our correct sounds and meshes and set that enumeration to be the correct thing. We can drag and drop these in so we can put it. I don't know why that sometimes does that. It's kinda weird. Just hit end and it'll go into its correct spot if it's weirdly somewhere else. I'm also not putting these in the correct location right now, but oh, well, it's okay. Like that. So now we should have our different hiccups, but there is no way to interact with them as of right now. So let's go ahead and fix that. So in our character in the and even graph where we put this, we have one called Action Mappings. Yes. So we have this line trace and I can do this, make this persistent tray now. So you can actually see this line trace and hit the E key. You'll actually see that's 200 sets. How far this is going out to actually interact with one of these. So you'll see this little square and it's red and then turns green to show that I actually hit something, actually interact with something. Snow hits it, look straight down on the ground, you'll get a hit right there, but it's hitting the ground. It's not adding anything of value to us. Okay, So that's kinda cool. Now if we were to have like a ton of things binded to this, to this interact. We would probably have some sort of and Event Dispatcher that we would just keep calling. But we only have two things in this project that we need to interact with. So that's why it's just done this way. So what we want to do is let's get our load out in, let's switch it on. And this is going to come out of that. Then we only want to be able to interact with ammo if we have a weapon. So like can't grab ammo without weapons, that sort of thing. And it's, but if we have a weapon we want to cast to recall it. Ammo, pick up base. Once again, this is going to come out of the head actor. Like that's that's, that's an okay spot. And then as the pika base, we want to run the event that we created. This one, pick up ammo. We want to actually run that. So we'll call it pick up ammo and then it's slots it in like that for us. So we can comment box, this whole thing quite honestly because this script is now done. And we'll put draws a line trace to check if trying to interact with MO or weapon pickups. Somebody like that. Yeah. Just make sure I spell everything correctly because I couldn't really see where I was typing. Okay, So that's what the script looks like that we just added this, this, this, so pretty self-explanatory there. Now if we come out here and I try to interact with any of this stuff, nothing's going to work. Even though we are getting green hits and we don't get an error, it's just running out of there. But let's say I pick up the shotgun and these three weapons. So the pistol. Oh gosh, which one's which? That's the epistle M0. So by interact with this, it doesn't do anything, but if I interact with this, it did the math, it disappeared. All of that. If I switch to the auto rifle, can't interact with this one or this one, or this one or this one or whatever. But I can't interact with that one. And then the shotgun can't do anything to anything but this one. Oh, I have the pistol grip. There we go. I got a little scared of resilience. I was like did I do the settings one? See, I can actually see those line traces now, what is kinda cool? Yeah, That is everything to do with our ammo pickups. It's how you do it. So cool. We're going to keep on rolling on key bad and some new features to the game. And then we'll finally, it's going to be really soon and we're going to actually start shooting these guns and doing some cool stuff with them. So I hope you enjoyed this video and I'll see you in the next one. 19. Shooting Hit Scan Weapons: Hello everyone and welcome back to another video. In this one, we're going to start adding some functionality to be able to shoot our hit Scan weapons. And between videos, I did a couple of just really small things. I added some texts renders out into the world. To do that, all you need to do is go into place actors and you can pull a text render out. You can rotate it. However you'd like. You can change the fonts, even though I don't think it'll work because it doesn't have a text material. Yeah. You can align it to the center, change the color or whatever you wanna do, and type in whatever you want it to say. So yeah, I but our weapon locker and then it will pick up. So I made it black and size 30, and I gave it a name and put it into a folder. And I also put our ammunition in the correct order and put that into a folder because they didn't call me organization station in high school for nothing. Actually, I called that. Moving on though, let's shoot some guns. So first thing we wanna do is in our data folder, right-click and go to blueprint and then go to enumeration. We're gonna go ie fired type. And as I said at the very beginning of the first video, we have two different types of weapons. The first one is called a hit scan, and the other one is a projectile. So if you remember, a hit Scan weapon is going to work with a line trace. A line trace being I don't think I debug this yet. So it's going to be the same type of thing where it draws an invisible line out into the world. And it's going to be an instantaneous looking for what it hits. So we'll get results like that with the hit scan, a projectile is going to be similar to if you were to just use the first-person template that comes with Unreal. That gun has a little yellow ball that comes out of it and it's actually a projectile. And the differences between projectiles and hit Scan, hit Scan, It's going to be an instantaneous hit. It's going to be a perfect straight line where as a projectile, we can set different speeds to it and have it be impacted by gravity. So our pistol or rifle and shotgun, those are gonna be hit scans and then the sniper rifle, grenade and Rocket are going to be projectile's. So in this video, we're going to start our script to be able to add functionality to the hits cantos, good, say reject. Ho. So yeah, let's go into our weapons folder and open up our weapon base. This is where all of our script is going to live. Alright? The first thing that we want to do here is let's go ahead and create a function and we'll call it start shooting. What we wanna do is we want to add an input to this and call it fire type In, make it of type, fire type, like that. Coming out of here, we want to make a sequence. And just like at other times in the class, we're going to add something out of the 1000. But for the sake of right now, what I wanna do is go out at that, then one pin and then we'll add this script later. That's where we're going to be controlling, actually decreasing the amount of bullets that we have and then doing some reloading stuff. But at a fire type, Let's switch that on and plug that into the then one pin like that, can reroute that node like that. Alrighty, So out of hits scan, what we wanna do is we want to call a different type of function. So not a whole lot added to this just yet, but we're going to have to create a new function. So let's call this Calculate hit or calculate a line trace. Let's call it that. And then this is going to have three different inputs. So let's add three inputs here. The first one is going to be a camera component. Second one is going to be a, a weapon mesh. And the third one is going to be a weapon socket. The camera is going to be of type. Someone could just camera component object. There we go. And then this one is going to be a scene components. Seeing component, object reference. Seeing component is like these things. Anything in our component like any of these components are considered a sink component. And then this one's going to be a name. Alright? What we can do here is let's pull out a sequence to undo a couple of different things. And we're going to promote all of these to local variables. Local camera, local weapon mesh, and local weapons socket, not sucker. Socket. Alright, and then let's just do this out of the, then the 0. And this is a little bit ugly. So let's maybe move all of this upward a little bit. And then add some reroute nodes like that maybe makes it a little bit off. It's tragic. I got to switch these two. Oh my goodness. This is just kind of an awkward first part of the script. For sure. To set all of these and Unreal do it and then not giving me the straight lines, which is an awful fate. Okay. But he gets the job done, yell, it gets the job done. So out of then one, Let's align trace for objects. Instead of by channel. We're going to do it for objects because we want to. So like line, if I were doing line trace by channel, you'll notice that it's missing this object types. So we only want our line trace to interact with a couple of different object types. So with this line trace by channel, it's just we don't have that option essentially in simplified terms. That's why we're using that one. All right, so what we want to do, similar to how we did this in the character, if you remember, took the camera component, god's location and did some math here, we want to do something similar. So let's grab our local camera component, which if you remember, is an input. So if I were to go here and I were to pull this out and say Calculate line trace. It's not going to be asking for that data because it's inputs. Okay? So local camera, we're going to get the world transform. And we want to split this struck pins that we can get a rotation, a location in a scale. Or I can use the scale, but we will use the rotation and the location. So the location of our camera is going to be our start point. So that's nice and easy there. But we're going to do several different things off of this endpoint. So let's actually start with the rotation and we'll get the forward vector. So the rotation of our camera straight out from that point is what we're getting. And then we're going to multiply this vector times float. I believe it as a float. Yes, UCS is k. So this is actually how far out into the world our line traits is going to go. So the other ones to 200. So let's make this something pretty vague, like 10 thousand distance line trace travels and if you want, okay. So like let's say you want to give a certain weapon more range then a different one. All you have to do is promote this to a variable. And then the line trace will go as far. So if you'd like a shotgun, it's hitting something from like, you know, across the map or something ridiculous. You can do that prefer simplicity sake right now. Well, let's just keep it like that. And we're going to vector plus a float compatible with. We might need to vector plus vector. Vector plus vector. Yeah, okay. Okay. Mathematics. So, yeah, this goes in here and then that goes in there. So what we're doing is we're taking location of our camera as a start point and then we're adding 10 thousand to that point. Now, normally, we would just add that into the endpoint and we'd be done in life would be good. But we like to make things more complicated because if you remember, we have this bullet spread thing going on here. So we don't want our line traces to be absolutely perfectly straight if we're not aiming down the sites. So how do we accomplish that effect? Well, let's do that right now. Okay? So out a vector, Let's break set a vector r, right? And then what we're going to do is let's grab our bullet spread, whatever that is set as default 350. And then let's multiply that by another float, and let's multiply that by negative one. Okay? And then what we wanna do here is we'll get a random float within a range. So. This node is going to be the minimum, and then this node is going to be the maximum. So, so our bold spread is 350. All right? The minimum value that this randomization can pump out is negative 350 and the maximum it can be as 300, 50. So OK, really enough though we need to get this for the x, the y, and the z. So we need to do this to other times. So we can plug one in for the x, one for y, and one for the z. So let's plug in the value of this and do all of the minimums in the value of this into all of the maximums, which yes, is, this is an abomination looking thing, but it's the best we can do. Okay, out of here, Let's add float, float, and we want to do that for x, y, and z. So I wanna make sure that we're randomizing this in all the locations x, y, and z. And then the return values will go into the bottom of that. Alright, this can get very ugly very fast. Trying to tame all these nodes here. Okay? And then add a here. We're going to make this a vector because we broke it. Now I gotta make it back into a vector again. All these float values into a vector again. And then last but not least, we need to actually check, okay? We only wanna do this if we're not aiming right? We only want this bullet spread to be randomly firing off like if we are Amy, we want it to be this perfect line, right? So guess what we need to do is out of a vague big and play, we need to get a reference to our player because they don't think we have one yet. So let's get the player character cast to the player, to variable and we'll call Player. I won't make it look beautiful just to save some time. I'll do that in between videos. Yeah, It's not liking me because for this, okay. So out of the return value of this, Let's get a select note like this. And actually that didn't pull up the way I wanted to. Let's get, let's try do it this way. Player, Let's get is aiming. And then let's make a select. Out of that. Ha-ha, there we go. That's what we want. So now it's grabbing the true and false. So if is aiming is true, then we just want to grab that. We just want to grab the perfect line. This the, the rotation of our cameras forward vector plus 10000 units out into the world. Want that to be perfect. But if we're not Amy, we want to do this little bullet spread math. So we want to plug that into the false. And then the return value of that's going to be our endpoint. In their complex. Not really. And I kind of sort of get out of here. Let's, let's make an array because we want to have multiple objects to interact with. The two that we want to interact with our world static and roll that dynamic. So these are the things that our line traces going to intersect. So if you go out into the world and you look at this and well, if you were to go into the collision settings of something, so maybe if I just grab this out of this Pollyanna son by default. So if I were to take this and Collision Presets and artists say this is Wars world, that ECUA, world dynamic there. Oh, I might need to. Or is it? Oh, there we go. This is what I'm looking for. A world dynamic, world static. So there's different things in the world that would be considered dynamic and static. I probably didn't need to explain that, but these are the object types we want. Object types we want are aligned to intersect with. But then we also want to ignore some actors. So let's get the player character. And I don't think this will plug in straight away. Okay, It just made an array. So we can add more things to this that we want this to ignore. Right? Out of this out hit. We want to, can we just do this? No, we can't. So let's add another pin. Let's add a return node out of this. And then let's make an outputs and make this hit result. And we'll call it hit result. And then plug that in like that. All right. That is the ugliest thing I've ever seen in my life. All right, so now we have our Calculate line trace thing here. So really quickly go over this. So we're setting the prompt me. We didn't even need to do the weapon mentioned the socket, set those as variables because we didn't actually use them. I thought we would potentially we only use the camera on or whatever. It's really not that big a deal to have them or not have them. It is what it is. So when we draw this line trace, we're getting the position of a camera. We have not specified what that camera is. Just yet. We're getting its location and setting that as our start point. And then what we're doing is we are taking the rotation of the camera, the forward vector from that camera, plus 10000, adding that together. And then if we are aiming, our weapon will return that as the end point. If we're not aiming, then we have break, broken that vector up into x, y, and z. We've randomized that number in between negative 315, 350, or whatever number that we said is this bowl as this bolt spread here. Then we're adding those two values together back up, making that into a vector again because we broke it and made it into floats. And then making that the endpoint. And we want our line trace to interact with world static and dynamic objects and ignore our player. We don't want it to interact with our player. All right, so now we have that function sitting out and about like that. And this part will be pretty easy. So let's grab the player and let's grab the camera. That's on the player. And that's going to be our camera. So we grab this, their camera for the weapon mesh. Well, let's just grab the weapon mesh from our base. That is nothing but it's set as other things in the the children. And then the weapons socket. Baba, baba, baba. So if I show you this, if we go to the weapons in a skeletal mesh, we want this is called muzzle flash. This is what we're grabbing. They're all called the muzzle flash. All right, so I don't need you the spammer promoted to a variable and we'll call it weapon socket, hence the name variable. And why is it not? Letting me? Ok, So it's up here. Okay. That was like, Well, we'll set that to be muzzle flash. I don't think we'll ever need to change that, but just in case he had a different weapon that you were to add to this project later on. You can now change that by a variable. So yeah, that's pretty cool. Okay, And then we're gonna do different things. It's returning whatever this hits so you can break it just to show you, we do all these different things but the hit result, the hits of the line, alright, and we're returning that value so that we can do cool things with that afterwards, which is exactly what we're gonna do, is we want to always do the cool things. All right, So all that set up looking pretty good so far. All right, So there are a few different things that we're going to add to all these scripts. But just to show you that this is working, Let's go ahead and just set it up as sort of a debugging thing really quickly. So let's go into our settings, project settings, and input. Create New Action Mapping and call it shoot, shoot, shoot, shoot. We call it fire. These are the I'm going to call it fire. I feel like shoot is just like manage shoot. Left mouse button. So we want to shoot. It's normally how it goes. All right, so in our event graph, let's go ahead and create an event. And we'll, we'll call this one fire hose that. So we're going to add things to this to make sure that we actually have ammo in a whole bunch of other things like that. Make sure that we're not like we actually can shoot our weapon. You know, uh, we can do that lecture right now because we created that variable. But it'll always be true, right? So let's just set that to be true for now. So we see that this works. Okay? Then let's get the current weapon. All right. And then we want to get the fire type. What what did we name that? Or do we not actually set that as a hole down a second or weight? Weapon type where it starts shooting is fired type of type var to 0. Okay, We put it in the input. We didn't actually make it a variable. So let's make that biotype. Okay, so now it has an actual variable of type flyer, type of hits scanner projectile. And that's important because we need to make sure that we set that in all of our children eventually too, so that it knows if it's a hit Scan weapon or a projectile type weapon. All right, so now let's get the fire type. That. So nice to us now. And we want to run start shooting. The target is going to be the current weapon and it's going to run out of the true branch and kind of jerry-rigged together right now, admittedly. But it should work. The last thing to do is go to Action Mappings and let's search for fire, the action event. And then let's just go run fire like that. So hopefully, my gosh, I've done it. Okay, we wanna make sure that we have this persistent, alright, And probably want to check that we actually have a weapon. So before we do this, let's go ahead and get the load out because that's what caused those areas errors. Errors. It's good, Leia kid. Okay. Pressed. Has weapon fire and we can see those lines. Right. Because it was set to be a persistent. Okay. Excellent. So no lines, no ears. Pretty good. So silica get that. So we're shooting right now and you can see those lines going out, boom, boom, boom, boom. And I go way out there. And if it's Seguin, see it's hitting stuff because it has the little line. And then these ones and I'm shooting out, don't do anything. So obviously the ammo isn't going down. We don't have any recoil. Whole bunch of stuff that we need to add. But there we go. I mean, our, our gun is shooting. We are drawing these line traces out into the world, which is exactly what we want to do. It is checking that you'd see that distance there. If I just draw one like that, you'd actually see. So from there to there, That's how Fargo. So like if you want to change that, if you don't want the shock and have that much range, go ahead and set that 10 thousand a year variable and then you can change that. And all the children say, I'm not a crazy like light show going on over here. Yeah. That looks kinda cool. See a o, you can see how it actually, I'm going to jump off them out. You can see how it actually keeps going through the green. So it's still goes through even though it hits something. Cool. That looks so yeah, all of that works. Yeah, that's everything. That's everything for this video. So we're going to keep adding stuff to this and making it more robust. We want to add the sounds and the effects and be able to reload and make sure that their ammo count actually goes down. And then also make the specific weapon weapons function, how they do make that assault rifle automatic and the shotgun is spread and all that stuff. But this is the baseline for what all of our projectile weapons are going to do, which is shoot out. And so now we have guns shooting, shooting with air quotes. So that will be pretty cool. So I hope you guys enjoyed this video and I'll see you next one. 20. Reloading Functionality (Part 1): Hi everyone and welcome back to another video. In these next few videos, we are going to be adding, reloading to our game. So in this video, this is mainly going to be the math behind it. So getting our current ammo to decrease whenever reshoot or gun in a game to understand like if we have 0 bullets in the magazine to automatically reload and just do different stuff like that. And then in future videos, we're going to actually add sound effects and an animation and in those types of things. So to get started in this one, we're going to go inside of our weapon base and we're going to create a decent amount of functions here. And between videos, There's a couple of things I did. I mainly just added comment boxes around things and made some of the stuff look a little bit nicer. So here's our Calculate line trace from the last video. So here's our bullet spread. Actors aligned truces going to hit the ones that will ignore. So just some added stuff. I got rid of those other two local variables because I don't think we're going to use them, but we do need them as inputs. We just don't need to set them as variables. And then I ended up getting rid of this weapon sockets variable. Because for my project at least every single socket is going to be muzzle flash. But if you want to use different weapons meshes that I'm using in the future. You definitely would want to set that as a variable so that any child of this weapon base, you'll be able to dynamically set that every single time. But I manually put it in. I think that's it. Other than that, I put some of our variables into different categories to keep them organized. Um, and like I said, if you can set this to be a variable if you'd like to as well. I just didn't because for simplicity sake, every line trace weapons going to be that distance for now. Okay? So I think that's everything. And yeah, we can get started. So let's start out by creating a function and we'll call this reload calculation. This will be controlling the math that we're doing here. For this, we're going to need a couple more variables to add to this OData, which is what I named it. So let's add a variable and we'll call this. So we don't have the CF magazine size. This is going to be of type integer. All these will be integers. So you have magazine size. And then we need one called bullet difference. Think that's it. We can drag those into category if you don't want to use categories, certainly don't have to. Just like if you open up a child, if you haven't been categories and they will show up into these little categories. If you don't do this, then that'll just be, they'll just be like one really, really long section there. So yes, let's get started out. So magazine size, this variable should always equal the current ammo. So our default is 30, so let's just set this to be 30. This is whatever just the size of our magazine is. This number's not going to change. The current ammo is going to change. But this is the total. So our magazine size, Let's get that. And let's get our current ML. And we're going to subtract these. And then we're going to set this as the bullet difference. Okay? The way I'm not going to create this whole function then just explain kind of what it does after the fact. Pulling out a bullet difference. We want to get a less than or equal to integer. And we want to get the current total AMA. And then let's pull out to branch here. Okay? Trying to just think of like when and how to explain what this is exactly doing. Well, let's just go, yeah, let's just go out in the true branch for now. And let's set not current ammo. And we're going to set that immediately for the true and the false. Excuse me. So scrap magazine size and plugged it into current ammo up here. And then we're gonna get our current total ammo. And the bullet difference. We're going to subtract these. Then we're going to set that as the new current total ammo. Like this. It looks pretty good. Okay, and then if this outcome is false, we want to grab the current ammo. The current total ammo. And we're going to add them together. And then we're going to set this as our current ML, like such. And then we want to set our current total ammo to be 0. Okay, so what is all this doing? All right, so here comes the math. So stick with me for a second here. So we have our magazine size. Let's say, let's just use 30 is 30. So our magazine is 30 and our current ammo is also 30. For the time being, let's say we shoot to round or five rounds, shoot off five rounds. So that means that this is 30 and this is 25. Subtract that this, and then this equals five. If five is less than or equal to the current total ammo, then we're going to do different things. So this current total ammo is a very large number. So more often than not, we're going to run this and I'll just say runs when there is reserve ammo. So more often than not, this function is going or this this isn't going to be true most of the time because our bullet difference is going to be relatively low numbers. The biggest number that this can be, as it would be 30, 30 minus 0. So the biggest disk could be, would be 30. So this is only going to run to the bottom if we run out of reserve AMA. Okay, So let's just follow along the true branch for now. So we got this equals 55 is less than or equal to 244. So we're gonna run up here. And our magazine size, which is 30, is going to be set as the current ammo. So in other words, this turn into 25. We're setting it back to the size of our magazine, which would be 30. And then we're taking our current total ammo, which is 244. We're subtracting it from the bullet difference, which in this case was five. We shut off five rounds and we're setting that as the new current total. So that would be 239. So what this is doing is it is taking, it's updating the big number. So 12 in this case would be the current and also the magazine size. So it's taking that number, it's setting that back to the magazine size, which is always going to be 12 in this case. And then it's just subtracting whatever that bullet difference was, how many rounds we shot off from that back-end. Small number 144. Now, let's say that we like run out of ammo or we don't have a lot of ammo in reserve. In this case. We're just going to do that math. So we're gonna take our current ammo. We're going to add it to the current total. Set that as our current because it won't equal the magazine size anymore because it won't have a full magazine to give us back. And then it's going to set the current total animal to 0 because we don't have any in the reserve. So this will run when reserve amount is lower than ammo magazine. So this is the math it'll do when there's like when you're running extremely low and ammo essentially. All right, cool. Now we're gonna do a couple of different checks. So let's create a new function and we'll say is MAG, full o