‫So the goal for this video is to have projectiles that actually launch through the air and behave as
‫projectiles should.
‫Hey, welcome back.
‫In this video, we're concerned with making our projectile actually behave like a projectile and move.
‫Now, there are different ways to handle this.
‫One way is to manually set the location and rotation of the projectile ourselves.
‫Now, this would generally require us to make the update every frame, so we would probably put this
‫in the tick function.
‫Another way is to simply add an impulse to the projectile and let the physics engine take over.
‫Essentially, we're applying a force and launching that projectile and letting gravity do its thing,
‫and the projectile will just fly off into the air.
‫Now, another way would be to use a movement component.
‫Now, this is a special type of component that we would add to our projectile class.
‫And after setting some parameters on the movement component, the movement component will handle the
‫movement for the actor.
‫Now it just so happens that Unreal Engine has a built in type of component made specifically for projectiles.
‫So this takes advantage of some of the built in features of Unreal Engine.
‫And by doing this, we allow the movement component to handle the movement for us based on the settings
‫that we provide.
‫So this is the method that we're going to use.
‫So we'd like to add a projectile movement component to our projectile class, and this is what will
‫handle the movement for the projectile object.
‫So as we spawn a projectile in the world, the projectile movement component which belongs to the projectile
‫class, can be set up and customized based on the variables on the projectile movement class that we
‫set.
‫Now we're going to set a couple of those, such as its initial speed and its max speed and the projectile
‫movement component will actually move the projectile in the world for us.
‫Now, here's the Unreal Engine Documentation page for you.
‫Projectile movement component.
‫This is the component that we're concerned with and you'll see that it says Projectile Movement Component
‫updates the position of another component during its tick.
‫By default, it's going to move the route component.
‫Now here's the include.
‫And if you continue scrolling down, you'll see some of the variables that can be set on the movement
‫component.
‫So scroll through this and take a look and see what the options are.
‫Now we add a projectile movement component to our class the same way we would add any other component,
‫which means you already know how to do this.
‫So your challenge is to go into the projectile class and add a you projectile movement component pointer
‫variable and expose this by making it visible anywhere.
‫And that way we can easily edit the projectile movement component from within blueprints.
‫Now you're going to construct it in the projectile constructor using create default sub object.
‫Don't forget to include the proper header and set the initial speed and max speed variables of the projectile
‫movement component.
‫Now choose your own values for these and set them in the constructor and then playtest the game.
‫You're going to adjust initial speed and max speed in the details panel by selecting the component in
‫the projectile blueprint.
‫And this will give you a little bit of experience tweaking parameters and experimenting as a developer.
‫So pause the video and create the projectile movement component now.
‫Okay.
‫So I'm here in projectile H and you probably added your component in the private section.
‫So if you did, you have the right instincts.
‫We're going to make this a private variable.
‫That's okay.
‫If you didn't, you can easily move it to the private section if you wish.
‫Now, this will be a U projectile movement component, and that's a pointer.
‫And we can simply call this projectile movement component.
‫Now, I'm going to give this a U property and simply make this visible anywhere.
‫Now, you probably gave it a category.
‫If not, that's totally fine, but I'm going to give it a category and call it movement.
‫So we have the projectile movement component.
‫I'm going to leave off the forward declaration and see if I can get away with compiling now here in
‫projectile CP, I'm going to include the header file.
‫So back to the documentation page, I'm going to copy this include and simply paste it in here in projectile.
‫And now I'm ready to construct my component.
‫So I'm going to say projectile movement component and I'm going to use create default sub object and
‫the type will be you projectile movement component.
‫And for the text, I'm simply going to call this projectile movement component just like that.
‫There's my semicolon and there we have it.
‫Now as instructed we're going to set projectile movement, component max speed, and I'm going to give
‫this an initial speed of, say, 1300 F This is something that we will experiment with and through play
‫testing will adjust this to the right value.
‫Now I'm going to set projectile movement component initial speed, and I'll set it to the same value.
‫So initial speed is going to be how fast the projectile component is when it starts.
‫And of course, it'll never go over max speed.
‫Let's go ahead and compile this.
‫Okay, so I'm getting a compilation error and if I go up I'll see that it's referencing projectile h.
‫So let's go back to projectile H and it says Projectile H 27.
‫It's referring to line 27 and that's this line right here.
‫And we get this projectile movement component is not a member of a projectile.
‫Remember, this was the type of error we saw when we didn't forward declare.
‫So we can easily forward declare this with the class keyword and compile again and we get a successful
‫compile.
‫So again, this is how we can learn whether or not a particular component is included by default.
‫And we saw that this one is not so with a successful compile.
‫Let's hop back in the editor.
‫Okay, so I'm back in the editor and I'm going to go into blueprints and actors and here is BFP projectile.
‫So here NP projectile.
‫Now I see that projectile movement component is here.
‫And in the details panel, you can see under projectile we have initial speed and max speed and you
‫can scroll through and see a lot of other parameters that we can set as well.
‫So let's play test this.
‫I'm going to hit play and left click and check it out.
‫Our projectiles are moving.
‫They are flying through the air and they stop once they actually hit something.
‫Now, eventually what we'd like to do is have them blow up and cause damage.
‫But this is a great starting point.
‫Now let's move within fire range and see if the turrets will spawn a projectile.
‫And of course they don't.
‫And the reason is because we have that TW subclass of variable.
‫So if you're wondering why the turrets weren't actually spawning projectiles, you may not have set
‫that.
‫So let's go ahead and go into ponds and beep pond, turret and open full blueprint.
‫Editor And we placed the projectile class in the combat section.
‫This is our subclass of so if we set this to BP projectile now our turret should start spawning projectiles
‫as well.
‫So let's get in fire range and there we have it.
‫It's shooting projectiles at us.
‫So this is looking awesome.
‫So we now have projectiles.
‫So let's take a look at our section plan.
‫We've already created a tank that can move throughout the world and we're now handling input with the
‫WASD keys and mouse clicks.
‫We've created an enemy turret class, we called it tower in C++ and we've added fire functionality with
‫projectiles.
‫Now next, we need to handle health damage and destruction in this game.
‫So those are our next steps and those are coming up in the videos to come.
‫So now that we've added a projectile movement component, we now have actual projectiles.
‫I'll see you in the next video when we start to talk about how we can make these projectiles actually
‫blow up and cause damage.
‫I'll see you soon.