All right.
I got a fun one for you.
This time, I'd like you to make some timelines for our fireball.
So create some timelines.
Maybe one, maybe two.
And I'd like you to make our fireballs fly out and then back in.
So they're going to fly out for a certain distance, at which point they slow down and come back to
aura.
And I'd like you to control their positions directly using values from the timeline.
And I'd also like you to make the fireballs come back to aura, and not just back to their initial launch
location.
That means if aura is running around, then those fireballs are going to probably need to adjust as
they're coming back.
So that's a little bit more of a challenge.
It's a little harder doing this than it is to make the fireballs go back to their initial launch position.
So take that into account, pause the video and conquer this quest now.
Okay.
So I'm going to make some timelines in our fireball blueprint.
But before we do that I'd like to make a function in C plus plus a blueprint callable one that we can
call to start the timeline.
And for that reason I'm going to close down the editor first and go into Aura Fireball.
And make a function.
We can make this public.
It's going to be called void start outgoing timeline.
And I'm going to implement this in blueprint.
So I'm going to make it a new function with blueprint implementable event.
So I don't need to implement it here.
In addition though, there's another thing that I want to expose to blueprint.
And that's an aura projectile we have on hit and on hit is handling, playing a sound, spawning a particle
system, and stopping the looping sound and setting a boolean to true.
This is basically doing everything except for destroy our projectile.
This would be useful to expose to blueprint as well.
So I'm going to make this one blueprint callable.
So give it a new function blueprint callable perfect.
And before launching back up I'm going to go into Aura Fireball and just go into begin play and call
my start outgoing timeline blueprint implementable event.
Just so we started.
And with that we can go ahead and launch the editor.
Okay, so I need to get my fireball open here.
And I need to implement start outgoing timeline.
So here's my event.
And I'd only like to control the location of this fireball on the server.
So first things first.
I'm going to check has authority and switch on that and only do anything if I have authority.
So what are we going to do if we have authority?
Well, I'm going to make a timeline to control my outgoing position.
So I'm going to make a timeline here.
And I'm going to call this outgoing timeline.
So outgoing timeline is going to get a float track and I'm going to call this outgoing track.
An outgoing track can have two points on it, two keys.
So I'm going to add two of them.
And how long do I want these fireballs flying out?
Well, I'm going to make it about one second long, so I'm going to set the length of my timeline to
one and set the first key at time zero.
With a value of zero, and the second key will be at time one with a value of one.
So this will be a normalized curve.
It's going to be something we use along with a maximum distance that we want our fireballs to travel.
I'm going to make it an auto curve and I'm going to shape it like this.
Because I want my fireballs to go out really fast with a high speed and taper off, and then slowly
come back.
Now we're not focused on coming back just yet.
This is just going out.
And how am I going to do this?
Well, I'm going to set actor location somehow.
So if I call set actor location.
We need some location to set in our update, right?
Well, what I'd like to do for my location is.
For one, I need a location to pass in.
So before we start the timeline, I'm going to calculate a location for my target.
At the end of the timeline, I'm going to call it the apex.
Apex generally refers to the highest point in an object's flying trajectory, but I'm referring to the
farthest point out as the apex.
So I'm going to calculate my initial location and my apex location.
So I have a start and an end.
So the start is going to be my current location at the time the timeline started.
So I'm going to call Get Actor location.
And I'm going to store this.
I'm going to promote it to a variable and call it initial location.
Now I also need my apex location.
How am I going to calculate that?
Well, let's get these three nodes here out of the way.
I'm going to take my forward vector.
So get actor forward vector.
And I'm going to multiply this actor forward vector which should be a unit vector.
By the way I'm going to multiply it by a float to scale it out.
Because I want it to be as long as my travel distance.
So I'm going to right click on this second pin, convert it to a float single precision and promote
this to a variable and call this travel distance.
And I can compile and give travel distance a default value if I like.
I'm just going to pick a number, say 1600, but we can tweak that value of course.
But now that I have this vector, I can add this to my initial location and that will give me my apex
location.
So if I take my initial location and I add and I add this vector which points out in the forward direction,
but it's scaled by travel distance, this gives me my apex location, and that's what I'm going to call
it apex location.
So now I have an initial and a destination.
And what I can do is use my outgoing track, which goes from 0 to 1, and I can lerp.
Lerp is a linear interpolation.
If I take my initial location and I drag off and type lerp, I can lerp vector passing in initial location
for a apex, location for B and an alpha.
Now what we get out of this node is a vector between these two, depending on the alpha.
If the alpha is zero, the return value is going to be a initial location.
If the alpha is one, the return value is going to be B apex location.
And if it's say 0.5, then we would get the vector in between these two it's linearly interpolating.
Well I can pass outgoing track into this lerp and take the lerp and pass it into set actor location.
And this allows me to set the location starting at initial going to apex, and will be smoothly going
to it according to our curve.
Let's go ahead and hook this up.
I'm going to just hook up play and I want to see what this looks like.
Now.
First I need to get my projectile movement component and disable it.
Again.
I'm going to go ahead and just put a zero in for initial speed and max speed.
Scroll down and disable everything from auto activate to wears.
Start with tick enabled.
There it is.
And with that we now no longer have projectile movement.
We're now controlling our movement here.
Let's see how it works.
I'm going to go ahead press play and hit the two key.
And there they go.
And they slow to a stop right there.
Pretty fascinating.
Right.
And we can change that travel distance.
That's the magic of having these member variables like this is if I change travel distance to 400,
I accidentally hit four twice.
I'm just going to leave it at 440.
Let's see what it looks like.
So over the space of a second, our projectiles fly out fast at first, but they slow to a stop, right?
So that takes care of the outgoing timeline, but I'm going to want them to come back in as well.
So before we do that, let's put some comments on this section here.
We're going to say store initial and Apex locations.
And this has a lot to do with vectors a lot of yellow.
So I'm going to make this a yellow comment.
And then after we've done this part a very important part here.
And I'll move this.
Let's see if we can overlap as little as possible here.
With our wires.
After this, our timeline is going to execute finished when it's done right and when finished, I'd
like to execute another timeline, one for coming back in.
So I'm going to right click and type timeline.
Scroll all the way to the bottom and add a new timeline and call this one.
Returning or incoming either one returning timeline.
And as soon as Outgoing Timeline is finished, we're going to play the returning timeline, and this
one is going to get a track of its own a float track called Returning Track.
And just like outgoing track, it's going to get two keys.
One, two.
The first one will be at time zero and it'll have a value of zero.
The second is going to get a time of one and it'll have a value of one.
And I can go ahead and normalize it and set the length of the track to one.
So why bother creating a whole timeline for this?
Well we can make this a different shape.
I'm going to make this an auto curve and shape it by grabbing the last key point and put it like this.
So the first curve looks like this.
We're starting off fast and slowing down.
The returning timeline curve starts like this.
It starts off slow and then gets faster.
So with our returning timeline, let's go back to our event graph.
We have our returning track and let's decide how we're going to do this.
I know for sure I'm going to be using set actor location, so I'm going to go ahead and hook that up
to update.
But how am I going to lerp this one?
Well, I can duplicate lerp.
And we're starting off at the apex location this time.
So that's going to be a but what's B?
Well, B needs to be the actor that we're returning back to.
So how do we know what that actor is.
Well we're going to have to set it somehow.
So I'd like to add a variable to our fireball that we can set when we spawn it.
Let's do that.
Let's go ahead and close the editor down.
We'll save all and we'll go back to our fireball and we'll add an actor.
So it's going to be a public variable just so we can set it from outside the class.
Let's make it a t object pointer.
And this will be an A actor.
And we're going to call this return to actor.
And we'll give it a U property and make it blueprint read only.
And we'll set this as soon as we spawn it.
So we'll go back to Aura Fire Blast.
And as soon as we've spawned the fireball, we're setting its damage effect params.
We're also going to set.
Its return to actor.
And what are we going to return to?
Well that's easy.
Get avatar actor from actor info.
And with that, we now have a valid return to actor.
We've exposed it to blueprint.
Now we can use it in our event graph.
Okay.
So we're going to go ahead and open.
And now in our lerp we can use Return to actor and we can get its actor location.
With Get Actor location.
We can hook that in for B and our track is going to go into Alpha.
So we can bring this up here.
I'm just tidying things up a bit.
And this will go into new location.
Now here's the thing.
As soon as we're done, I want to blow up.
So I'm going to place a branch right here after we've set the active location and blow up under a certain
condition.
Now, what is that condition?
Well, I want a specific distance that these should blow up as soon as they come back within that distance.
So I'm going to add a new variable and call this explode distance.
It's going to be a float.
I can compile and give it a value.
And I'll just make it say 250.
So when our fireballs are coming back, as soon as they're close enough, close enough.
Being 250 away, we're going to blow up.
So let's check that distance.
So first of all, we need to check the distance between this fireball.
That's get actor location
minus.
Minus what?
Minus the location of return to actor.
And after we have this vector, we get its length.
So we use vector length.
And we check this length.
We say, is this less than or equal to?
And we have our explode distance.
This can go into our branch and this could be a blueprint, pure function.
We can collapse.
The function we can call this is within explode distance.
And we can take this function and make it a blueprint pure by checking pure like that.
So that looks nice.
So if we should explode, if is within explode distance.
Well, we have on hit, don't we?
That's going to do lots of things for us.
It's going to make our explosion happen.
Now all of this happens on the server.
So if on hit happens then we can just destroy actor.
Let's see how this all works with our incoming timeline.
I'm going to save all first and press the two key.
And that looks amazing.
And the cool thing is, if we're running around, it looks even better because check this out.
Boom.
That looks so good.
Now I would like to change the travel distance because 440 is a little low.
I'm going to try 800.
I might even have it even more than that.
Oops.
Wrong spell.
That's the one.
Look at that and the explode distance is a little high, I think.
So I'm going to go ahead and change the explode distance from 250 to let's try 150.
I like it.
Now things are looking good visually.
But we don't cause any damage.
We'll see that they can pass through enemies, these fireballs, and they can even explode next to them.
Nothing really happens.
So we're going to need to make these fireballs functional.
But visually, this is looking pretty.
Pretty nice.
So awesome if you got through this whole challenge, congratulations!
I'm really proud of you.
And if not, don't worry about it.
We got fireballs now.
Things are looking great and we'll continue in the next video.