‫Hello and welcome.
‫In this lecture, we're going to be firing off the cannibals in the forward direction of the camera
‫and the cannonball itself.
‫So if I hit space, you can see that I can actually start to aim this ball at objects and try and hit
‫objects in the distance, which is a lot more fun.
‫Yes, I got that chair.
‫It's a lot more fun than it was previously.
‫Let's dive in and see how to do this.
‫So we're going to be using something called a forward vector, but what is it?
‫So I've just, on the sake of argument on this slide, puts in an X and y directions just like we would
‫have in the viewport to keep things grounded in that reality.
‫And we can imagine we've got our camera here, that is the player's camera that when we rotate the mouse,
‫it's turning around and we spawning it.
‫Now our projectile and the newly spawned projectile is getting the correct rotation from the camera.
‫So you can see this as I've depicted it on the slide.
‫Now, the forward vector would be essentially the rotated X direction.
‫So it is basically a vector that points in the forward direction after you have rotated it.
‫So you can see this projector has been rotated around and its forward direction is over here rather
‫than being off back towards the back of the camera because of the rotation that we've given it from
‫the Player Pawns Control rotation, now we can actually get a right vector as well, which is essentially
‫the Y axis that's been rotated.
‫But we're not going to be using that because all we're interested in is sending the projectile in that
‫forward direction.
‫And what's interesting about the vectors that come back from Get Forward vector and from get write vector
‫is that they have a length of one.
‫Less can be guaranteed.
‫They're always going to have a length of one.
‫And this is really useful because if we want to apply a certain amount of impulse in this direction,
‫all we need to do is multiply this vector to give us the direction by the value that we want, such
‫as 400, if that's the velocity you want to give it.
‫So enough torque, how do we actually achieve this in blueprint?
‫So what we need to do is query that newly spawned projectile.
‫We've given it the correct rotation over here before we spawned it, and it's been spawned with the
‫correct rotation.
‫We could see that when we play the game.
‫So we need to get its forward vector.
‫So to do that we can either pull off of the actor reference itself.
‫So the reference to the beep projectile which comes out of the spawn actor node, or we could do it
‫from the static component.
‫Either one would work just fine.
‫I'm going to do it from the actor just to save on nodes and keep things a little bit tidier.
‫So what we're going to do here is type in, get forward vector and we can see two options here.
‫I'm going to be using the get active forward vector.
‫Both would actually give you the same result and then we've got ourselves the vector value.
‫Now if we plug this directly into the impulse, we aren't going to see much of an effect.
‫If we go ahead and hit play and we spawn a projectile, you can see it just drops straight down.
‫And the reason for that is that the length of this vector is going to be one which, as we know, because
‫of unreal units, that's in centimeters.
‫So it's giving us one centimeter per second, which is a pretty puny velocity.
‫So what we need to be able to do is multiply this vector by a float.
‫Fortunately, we can do that fairly straightforwardly in blueprint.
‫We can drag off of the return value for this forward vector and we can type multiply and that gives
‫us this multiply operator node and you see by default what it wants to do is it wants to multiply a
‫vector by a vector, but that's not what we want to achieve.
‫And fortunately we can change that by right clicking on the second input node.
‫We can click convert pin and we can convert the pin to a float and that gives us the correct type of
‫multiplication that we want.
‫So I'd like to challenge you to do this multiply vector for yourself.
‫So plug in the multiplication node to both the input and the output to the impulse.
‫And how much do you need to multiply by to get a force that you are happy with?
‫Pause the video and have a go.
‫Hello and welcome back.
‫So we're going to I've already been using a value of about I think we said about 400 and then I'm going
‫to plug in the output from the multiplication into the input for the impulse.
‫So what we're getting is a vector that is 400 units long and is pointing in the direction, the forward
‫direction of our BP projectile, the way it's rotating.
‫And that is also at the same direction as our camera.
‫So let's go ahead and hit play.
‫And when we fire, you can see that it is firing off in the right direction, but with not quite enough
‫force.
‫So I'm going to increase this by make it 1000.
‫Let's try with 1000.
‫Okay.
‫We're getting something a lot better now that we can actually start to enjoy.
‫I think we had actually 4000.
‫I think I'm just misremembering, if we go ahead and play now with 4000, you can see a projectile that's
‫a lot more fun to fire.
‫And the final thing that I want to do is because we don't need to know it's rotation anymore.
‫And it kind of looks weird that it's this elongated shape.
‫I want to go back into the beep.
‫Projectile editor selecting the static measure component, go into the details pane and I'm just going
‫to set the scale back to 0.5 like all of the other elements there, which gives us the ball back to
‫being spherical.
‫And if we go ahead and hit play now, we've got a nice little cannonball, which is actually a lot of
‫fun to fire an objects and cause a little bit of destruction.
‫Great stuff.
‫We've achieved a lot in this lecture by applying that get forward vector node.
‫I'll see you in the next one.