Welcome back.
Now in this video we're going to take a look at the knockback that we cause from our Arcane Shards ability.
Now if I hit the enemy then knockback seems to work but the enemy goes straight up.
It doesn't really matter what direction I attack it from, it just goes straight into the air.
Now, it shouldn't really go straight into the air.
It should be flying away from my character.
If my character is over here to the right and I impart the knockback, then it should be knocking my
enemy away from my character.
Now, the reason it's not is actually a bug.
In my case, you might be seeing the correct behavior, but I'm not.
And the reason I know this is a bug specifically with this character is because I can drag in my other
characters.
I can bring in a demon.
For example, I can bring in a ghoul.
And let's get in a shaman.
And if I come back in here and I use arcane shards.
Then they're all knocking away from me.
All except that pesky little goblin.
It's just going straight up.
But the others, they go away from me.
So knockback is at least doing its job in that case.
But my goblin is bugged, so I'm going to have to create a new goblin spear.
I can do that.
I can right click on BP enemy base, create a Child Blueprint class and call this BP underscore Goblin.
Spear.
And I just need to set all of its properties.
So I'm going to time lapse while I just set all the properties for my goblin spear.
Okay, so now that I have a new Goblin Spear class, I can take my goblin spear that's defected and
delete it from the world first, and then go into Goblin Spear and delete the blueprint.
I'm going to force delete it.
And take my new goblin spear and move it into my Goblin spear folder and bring in one of these goblin
spears, and let's just see if that works as it should.
And it does.
Okay, so that's great.
But the thing is, what if I don't want my enemies to fly away from me?
What if I want them to fly away from the arcane shards themselves?
So if I spawn the shards on this side.
I want them to fly towards me.
In other words, I want the knockback direction to be calculated based on the location of the shard.
Well, I can do that.
Let's take a look at our shards ability, ability system, aura abilities, arcane arcane shards.
And we can open this ability and we can see where we're applying radial damage to player.
We're making effect params from class defaults and make damage effect params from class defaults.
If we take a look at that function in our Aura Damage gameplay ability class, we'll see how it's calculating
that knockback, it's setting knockback force based on a calculation from the avatar actor to the target
actor.
So that's why we're always knocking those enemies away from aura.
And of course, there's a rotation pitch that's an override.
Now we can pass in a vector if we like to set the knockback force.
So that way we would then be forced to pass one in in case we don't want this behavior for all knockback
forces.
Right.
We can do the same thing for death impulse as well.
So we can have a number of inputs for this.
We can have a knockback force direction that we pass in a death impulse direction, a pitch override
for these, and then perhaps a boolean for whether or not we should override our knockback force and
death impulse, or should we just calculate them based on the target actor.
So I'm going to add some more input parameters to this function.
So I'm going to put all of the inputs on their own lines, because there are going to be a lot of them
now.
And in addition to target actor and a radial damage origin, I'm going to pass in some knockback parameters.
Now I'm going to have booleans that I want to pass in to check to see if we should even override these.
Right.
So what I'm going to do is say bool be override knockback direction, and I'll give these default values
so we don't have to pass them in if we don't want to.
So it'll be false by default.
And then we'll have an f vector called in knockback direction.
Override.
We'll just call it knockback direction override and I'll set it equal to f vector.
Zero vector by default.
And I'll have a bool called be override.
Death impulse.
Set to false by default and have an f vector.
Def impulse direction override also set to an empty f vector.
The zero vector.
And then we can have a pitch override, and we can have a bool for whether or not to override it.
We can say B override pitch.
Equals false by default and a float pitch override, which is zero by default.
So now we have a whole bunch of parameters we can add.
So I'm going to go ahead.
And the quickest way I can do this is by clicking Generate definition.
Because now I have the correct signature.
And I can just copy the contents of my old function and paste it in the new one and delete the old one.
That's the quickest, laziest way to fix that signature.
Okay, so now we need to check a couple of booleans.
Right.
We should check whether or not we want to override our knockback direction and our death impulse.
So here's what we'll do.
We'll say if B override knockback direction then we'll override knockback direction.
Right.
And when we override knockback direction we're going to use the knockback direction override vector
only.
We're going to take that vector and override its pitch if we should override the pitch.
So if B override pitch then we'll override the pitch.
I'm going to do so by creating an F rotator called knockback rotation.
And that's going to be our knockback direction that we're passing in that are we're going to be override
with and call rotation on that.
So it's now a rotator.
And I'm going to take knockback rotation dot pitch and set it equal to the override pitch override.
And then I'm going to set my knockback force.
So I'm going to take params dot knockback force and set it equal to my new knockback direction which
is going to be knockback rotation dot vector.
And I'm going to scale it by knockback force magnitude.
And now we've overridden our pitch for knockback force.
Now, if we're not overriding the pitch, then all we need to do is set our knockback force equal to
the knockback direction.
Override times our knockback force magnitude.
So we'll do that first before overriding it.
We're going to say params dot knockback force equals knockback, direction, override times, knockback
force magnitude.
And of course we could take that knockback direction override and just make sure that it's normalized.
So we do that first we set it, and then if we override the pitch, we set it again.
And I'm noticing that knockback direction override is missing an R not the biggest deal but I'm going
to just fix it.
Knockback direction override with two R's.
And we'll fix it down here.
Okay, so we override knockback direction with the vector passed in.
If that boolean is true, and we override its pitch with the pitch override.
If that boolean is true, we're going to do the same thing now for our death impulse.
So we're going to say if B override death impulse we're going to take our death impulse direction override.
Make sure it's normalized first.
And then set params.
Death impulse equal to death.
Impulse.
Direction.
Override times.
Death impulse magnitude.
And then we'll check if we should override the pitch.
So if we override pitch.
We'll make an EF rotator.
Death impulse rotation.
Equal to death.
Impulse direction override dot rotation.
And we'll take death impulse rotation, dot pitch and set it equal to pitch override.
And then we'll set params dot death impulse equal to death impulse rotation dot vector.
Times death impulse magnitude.
So now we've got these overrides that we're doing.
And if these override booleans are false then we can set our death impulse based on this calculation
here.
And now that pitch override we're passing in is going to matter.
So I'm going to take this f rotator rotation.
And we'll just calculate it first up here.
So we don't have to calculate it twice if we need it at all.
And then we'll have an else case for both of these if statements.
We'll go ahead and calculate this two target.
Up here as well.
And we'll just check if be override pitch as well.
And if so we'll go ahead and override the rotation pitch.
We'll do that before we turn it into a vector.
So we'll do it right here.
If override pitch rotation dot pitch equals pitch override.
So we can still override the pitch even if we don't override the knockback and death impulse directions.
Once we have this two target, then we'll use it in the else cases here.
So we'll say params dot knockback force equals two target times knockback force magnitude.
And we'll set death impulse down here params.
Dot death impulse equals two target times death impulse magnitude.
And now we don't need this here.
Of course, we should actually check if the target actor is valid before doing any of this here.
So we'll just check it here.
We'll say if is valid target actor and then we'll place these here.
Of course these are now in the scope of this if statement.
So we might as well just check here.
If be override death impulse and if be override knockback direction.
And we'll just set these here.
We'll just set params dot knockback force right there and params dot death impulse right there.
And we could do knockback first if we want this to be consistent.
So like this.
And then we don't need the else cases down here I think this will be a little bit cleaner.
And if we look closely up here when our target actor is valid, we actually only want to set these vectors
if the corresponding override booleans are false.
So these actually need not here.
And finally, after all this we can remove this calculation which was setting our.
Knockback force and death impulse.
We no longer need to do it there.
And with that, we can compile and test this out.
Okay, so we're back in the editor.
I'm going to go into ability system aura abilities, arcane Arcane shards and open Arcane shards and
back in radial damage to player.
We can now start overriding some of these values and make damage effect params from class defaults.
And first I need to get that knockback direction, which I want to be the direction from my shard spawn
location to the target actor.
And to get that vector we can get the actor location.
And we can subtract shard spawn location from it.
This gives me the vector from the shard spawn location to the actor, and I can plug that into the knockback
direction override and the death impulse override, and I can check the checkboxes to override both
of those.
And I can also override the pitch with say, 45 degrees.
Maybe 35 degrees should be fine.
And with that we can test this out.
So I'm going to try to launch these characters towards Aurra by spawning the shards on the other side.
And there we go.
So where are those shards?
Spawn determines which direction those enemies will be knocked in.
Awesome.
Okay, so our knockback force is working pretty well.
And with that, we're just about done with our Arcane Shards ability.
We just need to make sure that the number of shards spawned is set based on our ability level, and
we can also use a description.
In fact, we could use a description for our electrocute ability as well.
So far, it's just our Firebolt that has a description so we can take care of those next.
And with that we now have three offensive abilities that work.
Awesome job.
I'll see you soon.