WEBVTT

00:06.810 --> 00:07.920
Welcome back.

00:08.220 --> 00:15.660
So now that we're sending client data to the server, we're now able to left click and the server will

00:15.660 --> 00:22.020
know where we're clicking, which is actually pretty significant because now our server will know where

00:22.020 --> 00:25.310
we're aiming and that's where we want to send the projectile.

00:25.320 --> 00:30.450
So in this video we're concerned with orienting the projectile in the correct direction.

00:30.510 --> 00:32.370
So let's go about doing that.

00:32.370 --> 00:37.020
I'm going to close the editor and I have ora projectile spell open.

00:37.020 --> 00:43.860
I'm going to close all other tabs and Ora projectile spell has a spawned projectile function.

00:44.040 --> 00:49.100
And if I open the H file, I'll see that we made this blueprint callable.

00:49.110 --> 00:53.850
Now I'd like this to take in a location in space.

00:53.880 --> 00:56.880
I'd like it to be the location under the mouse cursor.

00:56.880 --> 01:03.330
So as we're calling this function from our ability blueprint, we can pass that location in.

01:03.330 --> 01:11.100
So I'm going to make a const f vector by reference and we'll pass in the projectile target location.

01:11.100 --> 01:14.850
So we'll call this projectile target location.

01:14.850 --> 01:22.230
So let's go ahead and add this input parameter to our function, both in the H and CPP files.

01:22.260 --> 01:28.320
And now that we have this location, we can choose how to set our Transform's rotation.

01:28.440 --> 01:35.430
So we have the socket location and we know the target location as we're passing that in.

01:35.580 --> 01:46.110
So what we can do is make an F rotator called rotation and set this equal to the projectile target location

01:46.140 --> 01:51.540
minus the socket location that's going to give us a vector.

01:51.720 --> 01:57.450
So we need to take this vector and call dot rotation so we can get a rotator.

01:57.450 --> 02:03.240
So this will be the vector from the socket location to the projectile target location.

02:03.240 --> 02:09.910
Now that might be angled downward a bit because most of our targets are little guys and this is kind

02:09.910 --> 02:16.720
of a design decision, but I'd like my projectiles to fly parallel to the ground and I can easily do

02:16.720 --> 02:22.780
that by taking my rotation dot pitch and zeroing it out so I can set that to zero.

02:23.170 --> 02:25.060
And we have options here.

02:25.060 --> 02:32.470
If later we'd like to enable gravity on our projectiles, we could even make this pitch a little higher,

02:32.500 --> 02:39.490
say 25, 35 degrees, so that we launch the fireball slightly up into the air and then gravity brings

02:39.490 --> 02:40.560
it back down.

02:40.570 --> 02:43.180
So we may do that later on.

02:43.180 --> 02:48.700
But for now, we have a rotation and we'd like to set that rotation we have the to do here.

02:48.700 --> 02:49.990
So we're going to do that now.

02:49.990 --> 02:57.640
We're going to take our spawn transform dot set rotation and we're going to pass in a rotation.

02:57.640 --> 03:06.550
Now this requires a quaternion so we can take our rotation and use Dot Quaternion and pass in a quaternion.

03:06.850 --> 03:10.330
And now we should see our projectile fly in the right direction.

03:10.360 --> 03:13.420
Let's compile and launch and test that out.

03:14.550 --> 03:20.550
Okay, so we're back in the editor and we do need to pass something into that blueprint callable function

03:20.550 --> 03:23.730
so we can go to blueprints ability System.

03:23.770 --> 03:28.980
Gameplay abilities fire Firebolt and open a firebolt.

03:29.310 --> 03:35.970
Now we're currently not calling spawn projectile because we're just drawing a debug sphere.

03:35.970 --> 03:40.530
But what we can do now is take that location from our hit results.

03:40.530 --> 03:47.450
I'm going to collapse this node and this location can be passed in to spawn projectile now.

03:47.460 --> 03:51.860
So I'd like to cache this location into a local variable.

03:51.870 --> 03:57.540
I'm going to go ahead and remove my draw debug sphere and I'm going to take that location.

03:58.130 --> 04:04.010
And promote it to a variable and call this projectile target location.

04:04.010 --> 04:08.730
And we'll go ahead and just set that as soon as we have valid data.

04:08.750 --> 04:12.020
After that, we can play the montage and wait.

04:12.170 --> 04:17.810
So we'll take these nodes, move them up and call, play montage and wait.

04:18.020 --> 04:23.390
And then as soon as we hit Spawn Projectile, I'm going to take the projectile and pass it on in there.

04:24.110 --> 04:25.850
And then we end the ability.

04:25.940 --> 04:27.470
So let's see how this works.

04:27.470 --> 04:29.270
I'm going to go ahead and press play.

04:29.270 --> 04:36.770
I'm going to do this with two players, and for now I'm going to set the client off to the side and

04:36.770 --> 04:41.150
I'm going to take my server controlled character and click on an enemy.

04:41.150 --> 04:43.850
And we have a fireball now.

04:43.850 --> 04:49.790
Yes, our character is facing that way, but at least our fireball is going the right way.

04:49.880 --> 04:52.010
So that's a step in the right direction.

04:52.010 --> 04:53.480
Now, here's my client.

04:53.480 --> 04:58.760
I'm going to take the client and I'm going to click and I don't see a fireball.

04:58.790 --> 05:01.220
Now let's see what happens on the server.

05:01.220 --> 05:02.690
I'm going to take my server.

05:02.690 --> 05:04.880
Come over here, Here's my client.

05:04.880 --> 05:05.990
I'm going to click.

05:06.890 --> 05:09.620
No fireball on the server either.

05:09.620 --> 05:11.420
So what's going on here?

05:11.630 --> 05:13.790
Well, let's take a look at our firebolt.

05:13.820 --> 05:16.130
As soon as we call Spawn Projectile.

05:16.160 --> 05:16.790
Look at this.

05:16.820 --> 05:19.100
We're ending the ability right away.

05:19.280 --> 05:25.670
Now, this is happening on the server, and if this happens right away, it's going to cancel the ability.

05:25.790 --> 05:28.640
So let's see what happens if we just don't end the ability.

05:28.640 --> 05:30.950
I'm just going to go ahead and remove that node.

05:30.980 --> 05:34.760
We should end the ability in a more controlled manner there.

05:34.790 --> 05:36.680
Let's go ahead and press play.

05:36.770 --> 05:41.120
And here on the client, I'm going to click on an enemy.

05:41.870 --> 05:42.980
And there we go.

05:42.980 --> 05:43.730
That's better.

05:43.730 --> 05:49.610
Now, we can't reactivate the ability, but at least we know that we're spawning a projectile.

05:49.610 --> 05:54.200
And more importantly, we're spawning a projectile flying in the correct direction.

05:55.970 --> 05:58.640
So that is the goal for this video.

05:58.670 --> 05:59.840
We've accomplished that.

05:59.840 --> 06:02.240
Now, there are a couple things left to do.

06:02.270 --> 06:09.020
We're going to want our character to turn towards the direction of the Projectile's trajectory, and

06:09.020 --> 06:09.890
we'll do that soon.

06:09.890 --> 06:15.740
But another thing that's just kind of bothering me is when I move in front of the other character,

06:15.770 --> 06:21.440
the camera zooms in and that's because the camera is set to block the character.

06:21.440 --> 06:23.630
So let's just really quickly fix that.

06:23.630 --> 06:32.060
I'm going to go to Blueprints and character or a BP or a character, and let's first select our capsule

06:32.060 --> 06:36.790
component and see what the capsule has for collision.

06:36.800 --> 06:39.650
Let's expand our collision presets.

06:39.650 --> 06:43.160
And we see that it's set to block the camera.

06:43.190 --> 06:48.290
That's something I'd like to set to ignore, and I'd like to do that in C plus plus.

06:48.440 --> 06:53.480
Let's take a look at our mesh as well, both for the character and the weapon.

06:54.240 --> 06:56.970
And we see that it's Collision Presets.

06:56.970 --> 06:59.970
Has it set to block camera as well.

06:59.970 --> 07:04.740
And of course the weapon is probably also set to block the camera.

07:04.770 --> 07:11.190
It's actually set to no collision, so the weapon is fine, but the mesh and the capsule are set to

07:11.190 --> 07:12.090
block the camera.

07:12.090 --> 07:14.910
So before we wrap this up, I'm going to fix that.

07:14.910 --> 07:20.250
I'm going to go ahead and save all and let's open we'll do this on the base character class.

07:21.530 --> 07:29.870
So going into character and aura character base right here in the constructor, I'm going to take my

07:29.870 --> 07:32.950
capsule so we can get this with jet capsule.

07:34.640 --> 07:36.410
Jet capsule component.

07:36.410 --> 07:40.700
And I'm going to set collision response to channel.

07:40.730 --> 07:48.050
The channel will be XY camera and the response will be SDR ignore.

07:48.440 --> 07:50.150
We're going to do the same thing for the mesh.

07:50.150 --> 07:54.080
So we're going to call, get mesh and call the exact same function.

07:55.430 --> 08:00.680
And the weapon is fine because it's set to no collision, so that should fix that problem.

08:01.420 --> 08:04.270
We're going to run and debug mode and just quickly test it.

08:05.790 --> 08:06.480
All right.

08:06.480 --> 08:10.530
I'll go ahead and open those asset editors, but let's just go straight to the testing.

08:13.020 --> 08:14.340
And I think we're good.

08:14.370 --> 08:15.390
Perfect.

08:15.600 --> 08:18.930
Now, there's another thing I'd like to do, and that's that.

08:18.930 --> 08:20.760
When I left, Click on An Enemy.

08:20.910 --> 08:28.200
Yes, we can activate the ability, but if I'm over here and I click and I miss the enemy, well, I'm

08:28.200 --> 08:29.610
going to move to the enemy, right?

08:29.610 --> 08:31.620
And that is the behavior I want.

08:31.620 --> 08:38.100
But what if I want to just click between my character and the enemy and launch a fireball in that direction?

08:38.100 --> 08:45.120
What if I don't want to necessarily have to be hovering over an enemy whenever I fire a firebolt?

08:45.150 --> 08:47.160
Well, I'd like the option to do that.

08:47.160 --> 08:50.880
And one way is to perhaps hold the shift key down.

08:50.880 --> 08:58.650
If I'm holding the shift key down, I'd like to fire a firebolt So what we can do is make an input action

08:58.650 --> 09:00.120
for the shift key.

09:00.240 --> 09:05.760
So I'm going to go to blueprints, input input actions, make a new input action.

09:06.810 --> 09:08.820
So we'll go to input and put action.

09:08.820 --> 09:11.820
And I'm going to call this I a shift.

09:12.510 --> 09:18.240
And I a shift is going to be a axis1 D float just like the others.

09:19.740 --> 09:23.880
And we can add this to our input mapping context right here.

09:23.880 --> 09:32.550
Emcee Or a context, I'm going to click plus and choose my I a shift, and I'm going to click on the

09:32.550 --> 09:34.680
keyboard icon and hit the shift key.

09:34.710 --> 09:37.980
Now, this is the left shift and also like the right shift.

09:37.980 --> 09:39.540
So I'm going to click plus.

09:40.110 --> 09:43.710
And click the keyboard and hit the right shift key as well.

09:43.710 --> 09:50.670
So that way if we hit either shift, this will be triggered and then we can just really quickly add

09:50.670 --> 09:54.930
some functionality for this in our player controller.

09:54.930 --> 09:58.470
So I'm going to close out and open my player controller.

10:00.400 --> 10:02.230
I'm going to go to player.

10:02.380 --> 10:08.200
Player controller CP and find setup input component.

10:08.230 --> 10:09.040
Here we are.

10:09.040 --> 10:11.740
And I see that I'm binding the move action here.

10:11.740 --> 10:14.650
I'm going to bind a new action as well.

10:14.650 --> 10:16.540
I want a shift action.

10:16.540 --> 10:22.810
So I'm going to go into aura player controllers and add a new input action variable.

10:23.020 --> 10:25.060
So here's the move action.

10:25.060 --> 10:29.920
I'm going to add another one for shift and call this one shift action.

10:31.100 --> 10:34.480
And then back in player controller, we can bind it.

10:34.490 --> 10:43.340
So we're going to say aura input component, bind action, shift action.

10:44.530 --> 10:50.290
And we have some options we can do triggered, which is when it's held down.

10:50.320 --> 10:56.250
We can also do a trigger event started, which is when it starts and we can do released.

10:56.260 --> 11:00.490
I'm going to do two callbacks, one for started and one for released.

11:00.700 --> 11:08.240
Using the user object this and then we can pass in a function that we can use as a callback.

11:08.260 --> 11:10.870
So I'm going to make a callback function.

11:11.080 --> 11:16.030
Now these can take zero inputs or they can take an input action value.

11:16.800 --> 11:21.150
All I'm going to do is make a pressed and released function callback.

11:21.480 --> 11:29.730
So I'm going to make a void shift pressed with no inputs and a void shift released.

11:29.940 --> 11:35.520
And then I can just have a simple boolean for when our shift key is pressed.

11:35.520 --> 11:39.720
So this will be b shift key down.

11:40.290 --> 11:45.330
It'll be false by default and shift key pressed can simply set it.

11:45.330 --> 11:50.640
It can just have its body here and we can set shift key down equal to true.

11:51.600 --> 12:00.690
And we can also set it right here for shift released only we can set it to false and then we can bind

12:00.720 --> 12:03.210
these with bind action.

12:03.210 --> 12:11.880
So here we'll say or a player controller shift pressed and we can do this all over again.

12:12.660 --> 12:20.500
Only instead of started we can use completed and and we'll change this function to shift released.

12:20.800 --> 12:24.400
Now this way we'll always know if our shift key is down.

12:24.400 --> 12:28.510
If we check the boolean B shift key down.

12:28.690 --> 12:36.010
And that's something I'd like to check if our input tag is the left mouse button so we can check in

12:36.010 --> 12:37.990
ability input tag held.

12:38.020 --> 12:43.870
Now, if we're not the left mouse button, we're just passing the input tag off to the ability system

12:43.870 --> 12:44.770
component.

12:44.800 --> 12:49.390
Otherwise we check to see if we're targeting and then we do the same.

12:49.660 --> 12:54.280
But now we have this boolean to check if we're targeting.

12:54.280 --> 12:56.860
Yes, we want to tell the ability system component.

12:56.860 --> 12:59.860
Please try to activate the ability with this tag.

13:00.010 --> 13:04.690
But if we're holding the shift key, we want to do that same thing.

13:04.690 --> 13:11.710
So here instead of just be targeting, we can have an Or and say or B shift key down.

13:11.710 --> 13:18.250
If either of those is true, then we should tell the ability system component, hey, we want to activate

13:18.250 --> 13:23.620
the ability so we can't have the shift key down and expect to move and that's fine.

13:23.890 --> 13:28.780
Now, whether or not we're holding the left shift key, if we release that left mouse button, we still

13:28.780 --> 13:31.720
want to let the ability system component know.

13:32.080 --> 13:37.330
In fact, we should probably let it know whether we're targeting or not to, right?

13:37.330 --> 13:41.320
Because if we click on an enemy, we activate the ability.

13:41.320 --> 13:46.660
If we release after moving our mouse cursor, we're no longer on the enemy.

13:46.930 --> 13:52.330
Shouldn't the ability system component know if we've released the mouse button?

13:52.450 --> 13:59.320
So I think what we should do is we should inform the ability system component that we've released the

13:59.320 --> 14:00.820
mouse anyway.

14:00.820 --> 14:02.830
And now what about movement?

14:02.860 --> 14:08.080
If we release the mouse button, do we want to check for a short press threshold?

14:08.520 --> 14:11.070
Well, not if we're targeting right.

14:11.070 --> 14:14.160
And not if we're holding the shift button.

14:14.160 --> 14:21.630
So in other words, we do want something like if be targeting and if be shift key down.

14:21.630 --> 14:22.140
Right.

14:22.140 --> 14:26.250
If this condition is false, we would want this in the else.

14:26.250 --> 14:33.330
But now that we don't have anything in the if we can move this all to the if and change this to if not

14:33.330 --> 14:43.830
be targeting and not shift key down only now this has to be swapped from or to and and then all of the

14:43.830 --> 14:52.440
stuff in the else can be cut and placed in the if like so so we're telling the ability system component

14:52.440 --> 14:58.620
input is released regardless but it's only if we're not targeting and we're not holding the shift key

14:58.620 --> 15:03.560
that we check for a short press to see if we should stop moving.

15:03.570 --> 15:06.450
Let's try this out and see how it works.

15:09.010 --> 15:09.460
Okay.

15:09.460 --> 15:15.260
So what we need to do first before we test is we have to open our player controller blueprint.

15:15.280 --> 15:20.350
So in player player controller, we have to set our shift action.

15:20.350 --> 15:22.450
So here's a shift.

15:22.480 --> 15:25.090
We'll set that and we'll press play.

15:25.480 --> 15:27.790
So now we can test this out.

15:27.790 --> 15:29.110
Let's first try on the server.

15:29.110 --> 15:32.320
I'm going to click over here, I'm going to click on The Enemy.

15:32.350 --> 15:34.380
Everything works as expected.

15:34.390 --> 15:38.840
Now I'm going to hit Stop and play again as we're never ending the ability, right?

15:38.860 --> 15:42.700
And I'm going to hold shift and left click and.

15:44.060 --> 15:50.910
Just as expected, I was able to fire a fireball and if fires in the direction I'm clicking.

15:50.930 --> 15:51.620
That's great.

15:51.620 --> 15:53.300
Let's try it on the client.

15:53.300 --> 15:57.680
So I'm going to hold shift and click and it works.

15:58.940 --> 16:05.090
And if I hold shift and I click and I haven't ended my ability, so I can't activate it, but I can't

16:05.090 --> 16:06.410
move either.

16:06.860 --> 16:08.780
So that's great.

16:10.840 --> 16:14.560
What if I left Click and hold shift?

16:14.650 --> 16:17.920
Well, then it's going to trigger that ability.

16:19.990 --> 16:23.140
And if I'm running and I hold shift, I will stop running.

16:23.140 --> 16:27.490
If I click over here, I'm auto running and I hold shift, nothing happens.

16:27.490 --> 16:30.840
So that's something we should know about.

16:30.850 --> 16:33.280
So that's the behavior that we get.

16:33.280 --> 16:38.080
And of course we can always change it if we want different behavior, but that's what we get.

16:38.080 --> 16:40.480
And for now, it's looking good.

16:40.570 --> 16:43.600
We do have a couple things to change.

16:43.600 --> 16:51.010
For one, if we fire a fireball that way, we want aura to change directions and face that way.

16:51.010 --> 16:52.930
So we'll do those things next.

16:53.170 --> 16:54.150
Great job.

16:54.160 --> 16:55.210
I'll see you soon.
