Welcome back.
So now that we're calculating the spread, we're ready to spawn some projectiles.
But we're kind of repeating ourselves here as well as in or a summon ability here.
In fact, we've discovered a shortcoming of this algorithm and improved it here in Aura Firebolt.
And now that we have the formula perfected, it's probably a good idea to add a function for this in
a function library.
You see, needing some randomly spread rotators is actually kind of a common thing, and it would be
useful to have just a function on deck for that.
So I'd like to just put one of these into our ability system blueprint library.
Aura ability system library.
And this can be a static function.
It can return a t array of f rotators.
And we can get evenly spaced rotators about some spread.
So we can call this evenly spaced rotators.
And really all it needs is a forward vector and perhaps an axis of rotation.
If we want this to be really versatile so we can pass in a const f vector by reference called forward
and a const f vector by reference called axis.
And we'll have our function.
Now this gives us a t array of rotators.
But what if we wanted them in vector form.
We can make a vector version of it.
So we can make a static function that returns a t array of f vectors.
And we can call this evenly rotated vectors or something like that.
Evenly rotated rotators is a funny name.
I'm going to leave this at evenly spaced rotators, and we'll have evenly rotated vectors, and it'll
take the same inputs.
Now this could be a blueprint pure function.
So I'll go ahead and give it a new function.
And it's going to be.
It could be in gameplay mechanics.
That's fine.
As the category.
So both of these will be blueprint pure.
I'm going to go ahead and generate the functions.
And we already have the algorithm.
We just need to get it from a Firebolt.
So first thing we do is calculate our left of spread.
So we're going to get that line and paste it here.
But we need to know how much to spread.
So these functions also need a spread angle right.
So let's add that as well.
We'll make a float called spread.
That will be passed in to both of them.
So we got left of spread and it's rotating our forward vector by half of spread about the up vector.
But of course we're passing an axis.
So if we wanted to we could pass in something other than the up vector.
So that makes this a little bit more versatile.
Now the next step after we have left of spread is we do a for loop right.
So let's get this for loop here.
Including that delta spread.
So delta spread is going to take the overall spread.
And divide by the number of rotators that we want.
In other words, we need to pass in an integer here.
So we're going to go ahead and do that.
We'll have a int 32 called num rotators.
But our vector version will take an int 32 called num vectors.
So let's go ahead and add these.
So we get numb rotators and this version gets an int 32 numb vectors.
And I totally put this in the wrong place.
This num rotators goes here and evenly spaced rotators.
And then this num vector doesn't even go here.
I'm going to cut it and put it where it belongs there.
Now we should be fine.
And we don't need num rotators there.
Okay, so instead of numb projectiles we now have numb rotators.
We're going to use that.
Now we do need to make sure that numb rotators isn't one.
If numb rotators is one, well that's easy.
We can check if numb rotators is greater than one, then we'll do all this.
So we'll put this stuff in there and we'll have the else case.
Else.
And in this case we have only one rotator to provide.
And that's really just going to be the forward vector converted to a rotator.
So we'll just have a T array of F rotators declared at the top.
That will be for us to return.
We'll call this rotators.
Why is IntelliSense offering me this?
Potential name rotators.
It sounds like a variable name that Gollum would come up with.
I'm going to call it rotators.
So in the case rotators is going to be added to and we'll add forward into it forward rotation.
That is now that's not working because I see up here we have rotators.
That should be a T array of F rotator okay.
So now if num rotators is greater than one then we have delta spread.
We calculate that and then we loop.
We loop over the number of rotators.
So this will be num rotators.
And we'll calculate it a direction.
And that direction is going to be rotated by delta spread times I we don't need to draw a debug arrow
and we don't need a start vector.
All we need to do is take rotators and add to it.
What are we adding?
Direction rotation.
And by the end of this we can return rotators.
And looks like my typo is worse than I thought.
I called this rotators.
Oh, it's all the way back here.
Oh, boy.
All right, that fixes it.
And now we have evenly spaced rotators.
Now this is very much going to be similar for evenly spaced or evenly rotated vectors only we're going
to make a t array of f vector called vectors.
And we're still going to make a left of spread from the forward.
And if num vectors is greater than one, then we create that delta spread using num vectors, looping
over num vectors.
And we take our direction, we rotate it, and then we take our vectors and add direction to it without
converting to a rotator.
So it's the same function without that extra step.
And down here we're going to take vectors.
And just add foreword.
If we only have one and then we return vectors at the very end.
Okay, so we now have two nice utility functions.
And here in Aura Firebolt all we need to do is get those vectors.
We have a number of rotated vectors we can get from this.
So what I'd like to do is not even bother with left of spread and right of spread right.
And all of this stuff.
We can just make a single function call you or a ability system library evenly rotated vectors passing
in forward.
Our axis can be f vector up vector.
Our spread is going to be projectile spread, and num vectors is going to be num projectiles.
And now we have a tray.
Of vectors.
And we'll call this directions.
And why did I write vectors.
So now we have a 2D array of vectors for the directions.
And it would be wise to just make sure that our function does what it's supposed to do by simply looping
over directions.
So we can say for.
F vector.
Ref.
Direction and directions.
And then we can just use this.
Function call for draw debug arrow.
And we're going to use the start location socket location.
And the end location is going to be direction times 75 with all those parameters.
And the rest of this can be commented out.
And we can just make sure evenly rotated vectors works.
And while we're at it, it would probably be a good idea to do the same thing with the rotator version.
So I'm going to make a t array of F rotator.
Didn't say rotators because it would make me type it as rotators.
And I'm going to call this rotations and use you or ability system library evenly spaced rotators passing
in forward f vector up.
Up vector, projectile spread and numb projectiles and we'll just loop over rotations as well.
So this will be for each rotator.
We'll call it rotation I'll just call it root.
We have a rotation up there looping through rotations.
And then our socket location will be root dot vector times 75.
Let's just run this and make sure both of these work.
And actually before we test this I want to draw the rotation one in blue and slightly raised.
So I'm going to make an f vector start socket location plus f vector 005.
And we'll replace socket location with start.
Now let's try.
All right.
We'll get the ability open.
We'll see.
We have five projectiles.
Our spread is 90 degrees.
There we go.
Looks like both of our algorithms work just fine.
There's the rotator version.
There's the vector version.
We have two to choose from.
Perfect.
All right, so now that we know those are working, we don't need all this debug stuff do we.
So I'm going to go ahead and remove the debug stuff.
All of this.
I'm done with it I know my functions work.
Now what I need to do is pick one of these.
So I'm going to pick one of these.
And the one I'm going to pick is rotations.
So I have a t array of rotations.
And that just goes back to our aura projectile spell.
When we set a transform for the projectile we spawn we already have the location.
We just need to set the rotation for it.
And so for that simple reason I'm going to use rotations.
I'm going to use a for loop and loop over rotations.
We'll make a const f rotator reference for each iteration we'll call it rotation.
We'll just call it root looping over rotations.
And we want to spawn projectiles.
So let's look at our projectile spell.
We'll see that we have spawn transform made from socket location and rotation dot quaternion.
Let's copy that and put it in our for loop only.
Instead of rotation we're going to use root.
And now that we have spawn transform we can go about spawning a projectile.
And for now I'm just going to use the same code that we used in our projectile spell, namely just spawning
a projectile of this type A or a projectile.
I'll go ahead and include its type here.
I'm going to steal it from.
Or a projectile spell.
There it is.
It looks like I don't need gameplay tags there and back in aura Firebolts since I don't need Kismet
System library.
I'm going to replace it with Aura Projectile and I'm also going to collapse get description and next
level description so I can see what I'm doing here.
And we're spawning the actor.
We're spawning it spawn transform setting damage effect params and finishing spawning.
So with that we should see a number of fireballs come out.
Let's give it a shot.
All right, let's see if we get five projectiles.
Boom!
There they are.
Really cool.
Now I notice that the projectiles are spawning right away, and that's because I'm not hooking up my
event received to spawn projectiles.
So with that fixed now we'll get them spawned at the correct time.
Pretty cool.
And actually at this angle I can actually kill three of them.
I can hit all three, which is pretty nice.
Look at that.
Okay, so now we have the ability to spawn five projectiles at once.
And also with that pitch override, this is kind of cool because if I give it a pitch override of 45,
then we'll spawn it 45 upward, 45 degrees upward.
Now, obviously that looks definitely too high, but what if our projectiles had gravity?
Right?
Then it would be different.
So in the next video, we're going to work on giving our projectiles gravity, as well as making them
homing missiles so that our pitch override is going to look a little bit better when we set it to anything
other than zero.
With zero, they just go straight.
Like so.
Okay.
Excellent job.
I'll see you in the next video.