Welcome back.
So now that we're sending client data to the server, we're now able to left click and the server will
know where we're clicking, which is actually pretty significant because now our server will know where
we're aiming and that's where we want to send the projectile.
So in this video we're concerned with orienting the projectile in the correct direction.
So let's go about doing that.
I'm going to close the editor and I have ora projectile spell open.
I'm going to close all other tabs and Ora projectile spell has a spawned projectile function.
And if I open the H file, I'll see that we made this blueprint callable.
Now I'd like this to take in a location in space.
I'd like it to be the location under the mouse cursor.
So as we're calling this function from our ability blueprint, we can pass that location in.
So I'm going to make a const f vector by reference and we'll pass in the projectile target location.
So we'll call this projectile target location.
So let's go ahead and add this input parameter to our function, both in the H and CPP files.
And now that we have this location, we can choose how to set our Transform's rotation.
So we have the socket location and we know the target location as we're passing that in.
So what we can do is make an F rotator called rotation and set this equal to the projectile target location
minus the socket location that's going to give us a vector.
So we need to take this vector and call dot rotation so we can get a rotator.
So this will be the vector from the socket location to the projectile target location.
Now that might be angled downward a bit because most of our targets are little guys and this is kind
of a design decision, but I'd like my projectiles to fly parallel to the ground and I can easily do
that by taking my rotation dot pitch and zeroing it out so I can set that to zero.
And we have options here.
If later we'd like to enable gravity on our projectiles, we could even make this pitch a little higher,
say 25, 35 degrees, so that we launch the fireball slightly up into the air and then gravity brings
it back down.
So we may do that later on.
But for now, we have a rotation and we'd like to set that rotation we have the to do here.
So we're going to do that now.
We're going to take our spawn transform dot set rotation and we're going to pass in a rotation.
Now this requires a quaternion so we can take our rotation and use Dot Quaternion and pass in a quaternion.
And now we should see our projectile fly in the right direction.
Let's compile and launch and test that out.
Okay, so we're back in the editor and we do need to pass something into that blueprint callable function
so we can go to blueprints ability System.
Gameplay abilities fire Firebolt and open a firebolt.
Now we're currently not calling spawn projectile because we're just drawing a debug sphere.
But what we can do now is take that location from our hit results.
I'm going to collapse this node and this location can be passed in to spawn projectile now.
So I'd like to cache this location into a local variable.
I'm going to go ahead and remove my draw debug sphere and I'm going to take that location.
And promote it to a variable and call this projectile target location.
And we'll go ahead and just set that as soon as we have valid data.
After that, we can play the montage and wait.
So we'll take these nodes, move them up and call, play montage and wait.
And then as soon as we hit Spawn Projectile, I'm going to take the projectile and pass it on in there.
And then we end the ability.
So let's see how this works.
I'm going to go ahead and press play.
I'm going to do this with two players, and for now I'm going to set the client off to the side and
I'm going to take my server controlled character and click on an enemy.
And we have a fireball now.
Yes, our character is facing that way, but at least our fireball is going the right way.
So that's a step in the right direction.
Now, here's my client.
I'm going to take the client and I'm going to click and I don't see a fireball.
Now let's see what happens on the server.
I'm going to take my server.
Come over here, Here's my client.
I'm going to click.
No fireball on the server either.
So what's going on here?
Well, let's take a look at our firebolt.
As soon as we call Spawn Projectile.
Look at this.
We're ending the ability right away.
Now, this is happening on the server, and if this happens right away, it's going to cancel the ability.
So let's see what happens if we just don't end the ability.
I'm just going to go ahead and remove that node.
We should end the ability in a more controlled manner there.
Let's go ahead and press play.
And here on the client, I'm going to click on an enemy.
And there we go.
That's better.
Now, we can't reactivate the ability, but at least we know that we're spawning a projectile.
And more importantly, we're spawning a projectile flying in the correct direction.
So that is the goal for this video.
We've accomplished that.
Now, there are a couple things left to do.
We're going to want our character to turn towards the direction of the Projectile's trajectory, and
we'll do that soon.
But another thing that's just kind of bothering me is when I move in front of the other character,
the camera zooms in and that's because the camera is set to block the character.
So let's just really quickly fix that.
I'm going to go to Blueprints and character or a BP or a character, and let's first select our capsule
component and see what the capsule has for collision.
Let's expand our collision presets.
And we see that it's set to block the camera.
That's something I'd like to set to ignore, and I'd like to do that in C plus plus.
Let's take a look at our mesh as well, both for the character and the weapon.
And we see that it's Collision Presets.
Has it set to block camera as well.
And of course the weapon is probably also set to block the camera.
It's actually set to no collision, so the weapon is fine, but the mesh and the capsule are set to
block the camera.
So before we wrap this up, I'm going to fix that.
I'm going to go ahead and save all and let's open we'll do this on the base character class.
So going into character and aura character base right here in the constructor, I'm going to take my
capsule so we can get this with jet capsule.
Jet capsule component.
And I'm going to set collision response to channel.
The channel will be XY camera and the response will be SDR ignore.
We're going to do the same thing for the mesh.
So we're going to call, get mesh and call the exact same function.
And the weapon is fine because it's set to no collision, so that should fix that problem.
We're going to run and debug mode and just quickly test it.
All right.
I'll go ahead and open those asset editors, but let's just go straight to the testing.
And I think we're good.
Perfect.
Now, there's another thing I'd like to do, and that's that.
When I left, Click on An Enemy.
Yes, we can activate the ability, but if I'm over here and I click and I miss the enemy, well, I'm
going to move to the enemy, right?
And that is the behavior I want.
But what if I want to just click between my character and the enemy and launch a fireball in that direction?
What if I don't want to necessarily have to be hovering over an enemy whenever I fire a firebolt?
Well, I'd like the option to do that.
And one way is to perhaps hold the shift key down.
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
for the shift key.
So I'm going to go to blueprints, input input actions, make a new input action.
So we'll go to input and put action.
And I'm going to call this I a shift.
And I a shift is going to be a axis1 D float just like the others.
And we can add this to our input mapping context right here.
Emcee Or a context, I'm going to click plus and choose my I a shift, and I'm going to click on the
keyboard icon and hit the shift key.
Now, this is the left shift and also like the right shift.
So I'm going to click plus.
And click the keyboard and hit the right shift key as well.
So that way if we hit either shift, this will be triggered and then we can just really quickly add
some functionality for this in our player controller.
So I'm going to close out and open my player controller.
I'm going to go to player.
Player controller CP and find setup input component.
Here we are.
And I see that I'm binding the move action here.
I'm going to bind a new action as well.
I want a shift action.
So I'm going to go into aura player controllers and add a new input action variable.
So here's the move action.
I'm going to add another one for shift and call this one shift action.
And then back in player controller, we can bind it.
So we're going to say aura input component, bind action, shift action.
And we have some options we can do triggered, which is when it's held down.
We can also do a trigger event started, which is when it starts and we can do released.
I'm going to do two callbacks, one for started and one for released.
Using the user object this and then we can pass in a function that we can use as a callback.
So I'm going to make a callback function.
Now these can take zero inputs or they can take an input action value.
All I'm going to do is make a pressed and released function callback.
So I'm going to make a void shift pressed with no inputs and a void shift released.
And then I can just have a simple boolean for when our shift key is pressed.
So this will be b shift key down.
It'll be false by default and shift key pressed can simply set it.
It can just have its body here and we can set shift key down equal to true.
And we can also set it right here for shift released only we can set it to false and then we can bind
these with bind action.
So here we'll say or a player controller shift pressed and we can do this all over again.
Only instead of started we can use completed and and we'll change this function to shift released.
Now this way we'll always know if our shift key is down.
If we check the boolean B shift key down.
And that's something I'd like to check if our input tag is the left mouse button so we can check in
ability input tag held.
Now, if we're not the left mouse button, we're just passing the input tag off to the ability system
component.
Otherwise we check to see if we're targeting and then we do the same.
But now we have this boolean to check if we're targeting.
Yes, we want to tell the ability system component.
Please try to activate the ability with this tag.
But if we're holding the shift key, we want to do that same thing.
So here instead of just be targeting, we can have an Or and say or B shift key down.
If either of those is true, then we should tell the ability system component, hey, we want to activate
the ability so we can't have the shift key down and expect to move and that's fine.
Now, whether or not we're holding the left shift key, if we release that left mouse button, we still
want to let the ability system component know.
In fact, we should probably let it know whether we're targeting or not to, right?
Because if we click on an enemy, we activate the ability.
If we release after moving our mouse cursor, we're no longer on the enemy.
Shouldn't the ability system component know if we've released the mouse button?
So I think what we should do is we should inform the ability system component that we've released the
mouse anyway.
And now what about movement?
If we release the mouse button, do we want to check for a short press threshold?
Well, not if we're targeting right.
And not if we're holding the shift button.
So in other words, we do want something like if be targeting and if be shift key down.
Right.
If this condition is false, we would want this in the else.
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
be targeting and not shift key down only now this has to be swapped from or to and and then all of the
stuff in the else can be cut and placed in the if like so so we're telling the ability system component
input is released regardless but it's only if we're not targeting and we're not holding the shift key
that we check for a short press to see if we should stop moving.
Let's try this out and see how it works.
Okay.
So what we need to do first before we test is we have to open our player controller blueprint.
So in player player controller, we have to set our shift action.
So here's a shift.
We'll set that and we'll press play.
So now we can test this out.
Let's first try on the server.
I'm going to click over here, I'm going to click on The Enemy.
Everything works as expected.
Now I'm going to hit Stop and play again as we're never ending the ability, right?
And I'm going to hold shift and left click and.
Just as expected, I was able to fire a fireball and if fires in the direction I'm clicking.
That's great.
Let's try it on the client.
So I'm going to hold shift and click and it works.
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
move either.
So that's great.
What if I left Click and hold shift?
Well, then it's going to trigger that ability.
And if I'm running and I hold shift, I will stop running.
If I click over here, I'm auto running and I hold shift, nothing happens.
So that's something we should know about.
So that's the behavior that we get.
And of course we can always change it if we want different behavior, but that's what we get.
And for now, it's looking good.
We do have a couple things to change.
For one, if we fire a fireball that way, we want aura to change directions and face that way.
So we'll do those things next.
Great job.
I'll see you soon.